The things you learn

It was something like the spring of 1984, and I was (as usual) struggling in Professor Adelberg‘s class on Series and Differential Equations. And as usual, I took advantage of his office hours, on the second floor of ARH.

I don’t remember where the proof was supposed to end up, but I had about seven handwritten pages that sort of got me there. Not quite.

Professor Adelberg, sitting by my side at his desk, said, “Look, this is a 200-level class.” He paused slightly. “There are no seven-page proofs in a 200-level class.”

In this class, he said, you know you’re on the wrong track if your proof is more than about two pages. It’s a class full of people maybe a year and a half out of high school; we’re simply not at the level where theory gets that heavy.

Why am I telling you this?

I don’t remember very much in differential equations–I’ve always been more of a finite math and number theory kind of guy–but I remember that encounter because the lesson is always fresh. An answer that’s too hard is likely to be the wrong answer.

This morning, I had coffee with my homeboy Joe Fiorini, as a high-level pairing exercise. He was kind of busy, so we only hung out for about 45 minutes, which turned out to be an advantage. I’d been poking around at this JavaScript code for a day or so. All it had to do was maintain an array of user-selected IDs from a database table, show an HTML DIV of the IDs already selected along with descriptive data, open an HTML DIV to show a picklist of those not already taken, and let the user add the selection of another item, by choosing it from the picklist.

Its a “200-level class” sort of problem, isn’t it? But wow… I was cranking out that seven-page proof. Initializing the array. Refreshing the DIVs. Embedding links as A tags into the generated HTML. Making Ajax calls to repopulate the list in case it changed. I was getting a lot of mileage out of Firebug, which is never a good sign.

That’s about when Joe walked into the coffee joint.

I told Joe the story about Adelberg and the seven-page proof.

Joe said, “Let’s step back a minute. This is all in an HTML FORM, right? Why don’t you keep a hidden INPUT field containing the record ID in each LI? Then your array is right there. Not in the JavaScript.”

While I sat there flapping my face like a fish, because of course Joe was right, he went on: “And since this is a many-to-many relationship, you can set the NAME of that hidden field by convention to let Rails save it automatically to the join table.”

Which makes my Model logic drop-dead simple. It might even work by default. 130 lines of JavaScript will probably get cut down to a couple dozen.

Professor Adelberg, meet Joe Fiorini.