It's more than a house. It's an adventure.

Friday, March 31, 2006

I wish I could make this stuff up

As part of my documentation project, I'm having to dig deep into the inner workings of this system. And getting up close and personal with plenty of the code. It's just mind-boggling - some of it is written very elegantly (if oddly formatted), some of it is clearly the work of someone with little experience with the programming environment, or simply trying to stick to a "rule" that was pounded into their head.

Things like "write plenty of documentation in your code":var completed = false; //sets the value to falseGood, glad we got that cleared up. Or perhaps this one:while (j < 8) {
...
j = j+1; //increments the counter
}
(comments of this style are repeated a number of times in this function). Another repeater:codes[7] = "value"; //valueThen there's the date-parsing function which validates that the date you entered is valid. For example, making sure that the day is no more than 31 for January, March, May, July, August, October and December. That's all well and good - but why check each month individually, when same rules apply for all of those, and a simple IF statement will suffice?

But the real brain-buster is this. Every time any form field changes, it kicks off a function which scans through most of the form and hides/shows things, performs calculations, etc. And in addition to that global function, many of the fields have their own functions that that they run afterwards, in response to a change to the field. In terms of performance, it's kind of slow just because it's doing so much. Someone experienced with the app can actually get well ahead of the script with fast keystrokes. But what I found today...wow. When onchange fires for each of the fields in one group, the following happens. The top level in the list is the functions called directly from the onchange - subsequent levels are functions called by those functions, and so on.

  • Function1
    • FunctionA
      • Function2
      • Function3
  • Function2
  • Function3

Yikes? Function1 and Function2 aren't "huge", but they do a fair bit of math and date parsing, and call other functions themselves. At a very basic level, one could double the performance of this block of fields just by cutting out the redundant function calls.

I really wish I had the time, clearance, and reason to refactor all of this. But I'm documenting the system so that it can be replaced.

A friend likened my experience with this code to my experience with owning a 130-year-old house. It really is uncanny how similar the 2 are. The more I dig in, the more I find I need to change or fix. Or just find myself saying "what the...?"

0 Comments:

Post a Comment

<< Home