Thursday, 27 March 2008

Code horror

Here's something that was brought to my attention this evening, when I should be working on encounters for a Friday night WFRP game... no, instead I'm working. Literally. On a production problem. For my employer.

Scenario: a badly written stored procedure has a race condition. Instead of fixing the stored procedure, get the web geeks to fix it on the front end with Javascript. Problem: double clicking a submit button inserts duplicate records in the backend. Solution: stop users from double clicking, because fixing the database or the stored procedure is not the place you want to fix this problem. Whatever.

Assignment: get a flunky in a remote production support facility (we haven't left the US, fortunately) to craft a Javascript function that would prevent the form from submitting twice.

var submitted=0;
function checkAlreadyDone() {
        if (submitted < 2) {
                document.forms[0 ].submit();

There are a couple of problems with this charlie foxtrot. The first being the zero-indexed variable and the boolean check for less than 2! WTF? is that. Why not a boolean? It's easier to read. Now I have to do math to review the code. It's true or false! The second is I have think about what the variable state is on the round trip of the submission. 0, now 1, or less than 2. It changes to often.

I wanted to cry. And not just because the really broken code: the stored procedure and the database aren't going to be corrected, but because this is just badly written. The flunky never even requested a code review, never tested it because the call to the forms array was submitting the wrong form and creating a Javascript error in the browser! and basically broke the functionality of the page for over 6 million users.

Posted by caffeinated at 10:37 PM in 0xDECAF

New York City!? and nerd flattery

So, the reason I was in New York City is unveiled: job offer.

I'm gainfully employed as a web application architect at an international consumer credit issuer, but was “tapped” by a former coworker to come over to his new employer. Not one to idly dismiss such an overture, I joined him in New York to meet his bosses.

It went well. An offer was made.

A “fight” ensued between the two corporate giants... over me. A nerd.

Antes were raised.

My current employer won. But not because of money alone. Because I genuinely like working there. I have truly cultured deep friendships there. And while some of those same friendships have left for the company that tapped me, I think my decision makes the most sense for me. There were times in the last 24 hours, as I told my director, on conference calls, where I threw my hands in the air and asked, "why would I want to stay here, the person on this call builds technology like it was the Russian space shuttle1," but I would have those same calls at the new place I guess.

Well, I had to get this off my chest. I have been flattered in the last couple of weeks since my visit to New York City. Just doing my job as best I can, making the best decisions I can for those that pay me. And tiptoeing too. I don't want to burn bridges.

I can be the worse at tiptoeing. I can keep a secret, but I walking on eggshells, I always break a few...

meta-footnote-1=That's right, I slammed the Russian space shuttle program, trying to invoke stereotypes of cold war behemoth machines, mighty industrial visions of the simple ideas. Maybe there's a better stereotype. Whatever the metaphor, that's how this guy builds systems. I want to tell this guy The KISS Principle is not a band.
Posted by caffeinated at 6:21 AM in kaffehaus
« March »