Monday, November 24, 2008

Bad code

I'm a software engineer by trade, which means that occasionally I get to look into really old code that someone who quit years ago wrote (sometimes to make it do something that it wasn't designed to do in the first place, but that's another post), and I often find things that make me want to laugh and cry at the same time. Other übergeeks will understand this because they've gone through it too.

What follows are some examples that I've recently seen. I'll attempt to translate from geek to English as needed. All these were written in VB6.

If SW = True Then ...
This is like saying "If it is true that you are going to the store..." It's simpler to say "If you are going to the store..."

Delimited = FreeFile + 5
"FreeFile" is a function that gives you an available file handle number N so you can open a file with N and later read from or write to that file using N. Apparently the programmer decided that N plus 5 would be better. This is the equivalent of being told that parking space 11 is open and proceeding to park in space 16, even if another car is already there!

If IsNull(drs!TaxID) Then
   ...
   If IsNull(drs!TaxID) Then
    ...
   End If
Else ...

Translation: Check if tax ID is empty; if so, check it again! I left out some intervening code in this one, but it didn't change the TaxID in any way.

If InStr(ProviderName, "NULL") And Len(ProviderName) = 4 Then ...
If the thing contains the text "NULL" (a four-letter word) and the thing is only 4 letters long, then isn't the thing "NULL"? This should have been just If ProviderName = "NULL" Then ....

No comments: