JavaScript Date Wierdness

If you go to docs.jquery.com and pull open the docs for the datepicker and navigate to the month of November in 2008. You will notice that November 2 occurs twice in a row. Navigate to 2009, November 1 occurs twice. In 2010, November 7 occurs twice. We are using jQuery’s datepicker internally, so we had several users notice this for 2008, causing a colleague and I to dig into this problem. Also of note, is the fact that we tried this in Firefox 3, IE 7, Opera 9, and Safari and all of them produced the exact same results. After tracing through the jQuery date picker code, we came upon a line in the source (this was where the script was looping over the dates in the month, creating the table cells for each):

printDate.setUTCDate(printDate.getUTCDate() + 1);

When Nov 2 2008 was run through this code as printDate, it returned Nov 2 the first time and Nov 3 the second. Moreover, if you removed the expression and ran

printDate.setUTCDate(3);

the result was the same: Nov 2. In Firebug, we tried manually running the code and got the exact same result. Now, we found that changing this line (and all like it) to

printDate.setDate(printDate.getDate() + 1);

That is, using the regular date functions instead of the UTC versions, solved the problem and it solved it in all browsers. So, that leaves us with the question of why this was caused in the first place. It was nothing special to 2008, as it occurred in every year. At any rate, this solved our problem. I intend to do some additional poking through ECMA 262 to see if I can find the root of the problem, but I’ve got other fires to put out. We did find at least one other guy who was having a similar problem back in 2007.

Addendum: We played with this some more. The ultimate problem likes in the fact that the codebase mixes the use of regular date functions and UTC functions. Uniforming it either way solves the problem. This almost, almost makes sense–but not really. I still want to spend some time with ECMA 262, a pad of paper, and a pen and see if I can figure out why this is true. Maybe someone who knows a little more than I do about the specifics of the JavaScript Date object implementation can shed some light on this.

Tech Joys

Post hard drive failure, I am resetting up the white box I use as a home server (sure, the dirty old machine is well short of being a paragon of computing power, but it suffices for the simple purposes to which it is put). After installing FreeBSD on it (I had Gentoo before the failure–I like to keep abreast of various OSes) I am going through the ritual of compiling and installing the software I wanted through ports. As I watched pages of compilation messages and warnings earlier this evening I found that the whole thing was relaxing. Laugh if you will, but I actually enjoy building the software from source that way (that said, I lack a bit of the patience to go out and manually grab source for every library and package; we need computers to automate work, not add it). Now, unless I were doing some special performance tweaks for something mission critical, I couldn’t justify building the server that way at work. Even with FreeBSD, which we don’t use at the shop I’m at, I would feel much more compelled to simply install the binary packages and roll on. After all, if I am building a server we need a server built! But when I am working on my own, I usually want the result–but I can live on until it is done. So I can relax. Take the time to make sure that it is done right, to experiment and create a more interesting set up (which sometimes conflicts with the previous item), and just, in the software sense, stop and smell the roses. We spend so much time professionally trying to keep the trains moving that it is nice to be able to sit in the depot and watch them come in.

A few months ago, I got off a binge of contracting work (most of it vestiges of prior work done while I was trying to stay alive with it between jobs). For a good while, I coded at work then did nothing on my computer at home. After so long of PHP/MySQL from dawn to dusk, I needed a break. Then, I started working on Latrunculi again. I continued the scarcely started subproject of moving it over to Common Lisp (which is now the version in trunk, showing just how far along it has come) and enjoyed refactoring the code, removing issues with the original implementation (some my stupidity, like an overreliance on global variables, and others a library’s fault, like the wierd way that threading worked in Chicken), and picking up Common Lisp. I got to do three things that most of us do not really get to do at work: concentrate on perfection, exploratory programming (programming to explore and learn, rather than to merely crank out code for the next deadline), and use a slightly out-of-mainstream language. The first time I did this after a while, I almost literally got a rush of euphoria. That was how good it felt.

The tech joys, for me, are the common elements between the two tasks: concentration on perfection, learning, and using alternate technologies. I could natter on here about how these things make you a better tech anyway (they probably do, but I think that most advocates fail to prove that it actually makes its practitioners better or whether those who are better at their trade are not more apt to also enjoy doing it off hours; there is probably a measure of truth to each), but I won’t. I’ll leave that to others. Instead, I’ll just say that at times when the house is quiet, my wife and son asleep, and I am stealing a few minutes to bask in technical geekery, I thank God for giving us such wonderful toys for the human mind.

Catching MUMPS…

The first time I had ever heard of MUMPS (also known as the M programming language) it was in an entry on the awesome Daily WTF. After the first pass through the article, I assumed, like several other people, that MUMPS was a cooked up name for a language whose identity was being protected. However, one very helpful commenter wrote that the language did, indeed, exist and had not been anonymized. Recently, the PLNews blog announced that there had been a new release of an Open Source MUMPS compiler/interpreter system. Curious, for reasons of archeology, if nothing else, I downloaded the source and compiled it. Then the fun part: I started playing with this relic.

Mumps documentation is a little hard to find. I suppose that the mere fact that some can be found is, in itself, a small miracle. The only real guide (aside from buying a book; 40 bucks isn’t a bad investment if you are doing this professionally, but for the casual tinkerer it seems sort of ridiculous) that I found was the quick and dirty manual that came packaged with the compiler itself.

The language itself is not unlike BASIC (and, I assume, COBOL or RPG) in spirit. The familiar procedural idiom is highly visible when looking at snippets like

> set a=”foo”

> write a

foo

and is mostly interpreted (the manual indicates that, according to the M language spec, it is impossible to create a fully compiled M program that includes all the relevant features).

The most interesting feature of the language is none of its BASIC-esque glory, but the way it handles what are termed global arrays. Arrays in M/UMPS are, basically, multidimensioned hashtables. These themselves act like the arrays you would be used to if you have used PHP or Perl (as an interesting note along these lines, the $ sigil is basically the opposite of the one used in PHP, variables, or Perl’s scalar variables; it is used to, instead, denote functions). Once one uses the ^ operator to access “global arrays”, one is no longer simply working on the currently running script. Rather, this data is written directly to disk in a tree-like structure which is not unlike the representation used by modern database systems. In addition, basic set operators are included in the language.
It is this whole idea that interests me. In many domains, this idea would be either nonsensical, but for most business apps that is all we really do. We read the database, do some processing, and write it back out. This model goes completely out the window for such programs as Latrunculi or Ocean that I am working on right now, neither of which use a database.

However, as I indicated, virtually every business application on the planet has this core workflow, even if the operation is to chew up some data and spit out some pretty pictures. Where does this leave us? All programs are stored procedures running on the database (or, all stored procedures are programs at the main computer’s level; however you want to see it). Now, there has been a great deal of talk about keeping all of the database layer in and of itself. This method of doing things seems to have, by and large, been passing in favor or using prepared statements in the main application code, eliminating the middle man of stored procedures. For better or worse, this makes the whole idea of separating a database intensive application (which is what every tracking, accounting, or point of sale system really is) more or less superflous. Alex of the Daily WTF even wrote an article on this subject. The reason why the line between the business rule layer and the data access is so blurry is because the line itself is really nonexistant. Business rules are little more than a description of what data we want to retrieve and what calculations we want to run.

I wonder whether a language like M might not have a place in today’s world. Replace the BASIC side with something more reminiscent of Python, Lisp, or Haskell and you might very well have a winning platform. Probably with a friendly ALGOL like syntax (making it more like JavaScript or ActionScript than any other language I have mentioned so far). Like I said, not applicable for everything in the wide old world, but a language like this would fulfill a wide need. Of course, in addition to bringing the main language itself up to date with such goodies as lambda expressions, the database backend itself would need to be overhauled to support finer grained querying, concurrency, clustering, and replication. Oh, well. All part of being a “programmer archaelogist”.

What I hate about MySQL

MySQL has gotten better as time has gone on. I want to make that clear up front before I bash a handful of things about its current state. It has gone from being little more than an SQL front end to flat files to being almost a real database (if you use InnoDB and friends).

  • No full outer join; this one irritates me to no end when working on diff-type queries (ones that, like the diff utility in UNIX, take a set of rows and compare them against another set, getting a difference) because I have to union three queries together, rather than simply one query with a full outer join.
  • Constraints and concurrency are not enforced by default. You have to setup InnoDB to make it work properly. There is simply no excuse for not maintaining relationships in a RELATIONAL DATABASE. InnoDB is great, don’t get me wrong, but I should not have to setup an add-on (and to run properly, you will need to configure the engine, at least a little) to get something so basic and fundamental. With MySQL 6.0, Sun has promised an end to this with Falcon, but that has yet to happen. 6.0 isn’t out yet, and it wouldn’t be fit for production use for a while longer even if it were.
  • Stored procedures. These were not added until version 5.0 of MySQL (many shops and shared hosts are still on 4!), but now they are here–sort of. The fact of the matter is that stored procedures really aren’t usable in MySQL. The syntax is clumsy, requiring messing with delimiters to even create them. They do not work from the command line because of this, which makes testing harder. In addition, the syntax is lacking quite a bit featurewise. The easiest example of this is also what should be simplest: how do you iterate over a cursor? Simple 101 feature, right? Not really. At least, not in MySQL.

Those are the biggest things I can think of off the top of my head. I’ve got a hunch that I would not be happy about replication or binary logging either if I had the time to set them up. Now for any of you reading this (if anyone does read this), you may ask: why not just use PostgreSQL? Or Oracle? Or even Microsoft SQL Server? The shop I am working in will not invest the sums for Oracle or MS SQL Server, so those are out. The current reality is that we will not be leaving MySQL any time soon.

QuickBooks and ASP.NET

Let’s start out with a scenario: we have a series of web apps for internal use (running on LAMP boxes) and we want the data to be pushed into QuickBooks semi-automagically. We wanted more magic and less semi, but the accountants wouldn’t let us. At any rate, we wanted to keep the same setup. We eventually got things working, more or less, by running a web service in ASP.NET on IIS on the same machine as a Quickbooks instance and letting the PHP side talk to that through SOAP. It works pretty well on the whole, but getting QuickBooks to interoperate with ASP.NET turned out to be a pain. After Googling, trial, and error, here are the steps I took to get the libraries to work all happily:

  • Install QBFC and qbXMLRP2; if you installed the SDK, the installers will exists on your hard drive. The filenames are:
    • QBFC8_0Installer.exe (install with the command¬† QBFC8_0Installer.exe /v”ALLUSERS=1″)
    • qbXMLRP2e.exe (install with the command qbXMLRP2e.exe /RegServer)
  • Go to Control Panel->Administrative Tools-> Component Services
  • From there, navigate to Console Root->Component Services->Computers-> My Computer->DCOM Config
  • Right click on qbXMLRp2e and select properties
  • Here, you are going to grant permissions to the various users associated with an ASP.NET call so that the COM calls can be made
    • Click ‘Customize’ in the ‘Launch and Activation Settings’ section
      • Grant ‘Local Launch’ and ‘Local Activation’ permissions to the following users:
        • Network Service
        • ASPNET
        • IUSR_MACHINENAME
        • IWAM_MACHINENAME
        • INTERACTIVE
      • Where you need to substitute the name of your machine for ‘MACHINENAME’
    • Click ‘Customize’ in the ‘Access Permissions’ page
      • To the same users above, grant ‘Local Access’
  • Finally, fire up QuickBooks and log in (preferably, with a user specially created for the purpose).

The long and short of it is making sure that the correct permissions are assigned to the correct COM components. In our setup, we left QuickBooks running constantly on a dedicated Windows XP virtual machine. I am unsure whether there is a better way to handle this, but it does not really seem like there is.
References

Pizza Experience

I usually keep this blog pretty much on-topic (the topic being a conglomeration of computer-related topics that I am interested in or working on), so I don’t feel bad about wandering off once or twice.

Last night, I had a pizza experience. My wife and I ordered a pizza and as we were eating it, I noticed one line printed on the side of the box:

Your pizza experience was managed by Joshua

Now, Joshua, should you, perchance, come across it the pizza was good. And I get the point. If I have a complaint, ask for Joshua. But that is one of the worst examples of PC sales talk I have heard in quite a while. My “pizza experience”? Are you talking about the food or the rumbling my stomach does all night after eating a few slices of it? What the heck is a “pizza experience”? And why, for pete’s sake, does everything have to be an “experience”? From using Windows to eating pizza, marketoids intone about the “experience”. Shut up about this ethereal “experience”. Eating pizza is not achieving nirvana. Using the OS does not make me giddy (what it enables me to do can, but not manuevering the system itself).

So, knock it off with the “experience” and just give me good pizza.