Crimes against good coding practice

I did software as a contractor for various federal agencies for years. It was a good gig for the most part – I got out when they wanted me to write less code and go to more meetings. I can assure you that I did NOT go into software because I wanted to go to meetings.

We were often forced to code in very strict and unfriendly conditions. I like to compare myself to the early Nintendo developers, who I believe had to use short variable names to save space, which seems utterly absurd now, but so do a lot of things.

Anyway, we had this custom web application framework that my then-boss had built. In many ways it was a glorious triumph of engineering. In many other ways it was a steaming pile of garbage. It had to run on an Oracle application server. It was written in PL/SQL. It worked well, but it was deeply flawed in ways I didn’t really understand then, but in hindsight I sometimes have nightmares.

One of the things it did really poorly was form submission. The web framework required a consistent url structure and was completely inflexible on this. For some reason we were not passing form values in POST – I didn’t understand the difference then, and probably no one else on the team did, either. None of us had gone to school for programming. In our application, there was this big procedure that had a giant conditional that took in parameters and then decided which procedure to call to build the intended web page:

if page == 1 then home() else if page == 2 then page2()

Something like that, except there were like 100 entries. The problem was that this procedure expected all parameters as url parameters. So if you wanted to record that Bob had made 10 widgets today (this is not what our website did but you get the idea) you had to write a url like:"Bob"&widgets=10

Except that didn’t work with the show procedure. It had to be consistent – if you passed “employee” to show in this context, you had to pass it for every page in the website. The solution for this was to pass a bunch of pairs of parameters – a name and a value – so it was consistent. So now you had to write your url like:"employee"&varval1="Bob"&varname2="widgets"&varval2=10

There was this hacky bit of Javascript that would take a form and translate it into this format for submission. It was less than ideal. But it worked. And really, as a coding practice, I FEEL this. The guy who wrote the web framework got it to where it worked for him and then left it. We’ve all done that on code we use for ourselves. Yes, even you have done it, don’t lie. But this got annoying really fast: “Was employee varval2 or varval3”?

So what I did, and let me tell you I was smug AF about this – I wrote a show2 procedure that expected all the parameters as one JSON-formatted variable. Now, I wish I could recall whether or not I started POSTing the forms or if I still put it in the url. Let’s say I POSTed it because no one who can say I didn’t is ever going to read this. But now you had something like this:

{"page":2,"employee":"Bob", "widgets":10}

Much better. Not good, but better.

Leave a Reply

Your email address will not be published. Required fields are marked *