Joe White's Blog Life, .NET, and cats

Whiskey Tango Foxtrot #Delphi

We've been refactoring some legacy code over the past few days, and we've found a couple of amusing snippets. They were written by programmers who no longer work here, so we can poke fun at them.

Here's an interesting bit from 1998:

try
  // do some stuff
except
  raise;
  ShowMessage('Duplicate ID: ' + IntToStr(NewID) + #13 +
    'TableName: ' + tblNewRow.TableName );
  tblNewRow.Cancel;
end;

So we'll cancel the append even if the re-raise fails, and execution falls through to the line after the raise. I can honestly say that this bit of resource-protection code never would have occurred to me.

A co-worker found another gem yesterday. This one also dates back to 1998 (though written by a different programmer):

Query.Locate(Query.FieldByName('ID').FieldName, ID, []);

So we call FieldByName, which searches for, and returns, the field whose FieldName is 'ID'... and then we read that field's FieldName. Brilliant, no?

I'm sad to say, though, that these coding gems are no longer in our code base. Somehow, they got lost during some code cleanup. I can't tell you how much that distresses me.