Archive for November 2009

StringList Comparison

A few weeks ago I wrote about using the List Comparison algorithm to optimize a slow nested loop.  This evening I saw someone on the Delphi forums asking about a way to compare two TStringLists, so I wrote up a quick version of the List Comparison algorithm specifically for TStringLists.  I used the basic algorithm as a higher-order function that you can pass method pointers to to configure its behavior, and added a few built-in comparison functions that perform common tasks.  You can find it in the Downloads page.  I’m working on a List Comparison library that uses generics and anonymous methods to compare TList<T> descendants, but it’s not done yet.  I’ll post it here when it’s ready.

As-sertion casting

So you’ve got some code that you know has to be in a certain state. It can’t be proven at compile-time, but you know that it has to be like this, and if it wasn’t, it could cause some serious problems. But you’re a good, careful coder, and you don’t want to just assume that the state of the program will be a certain way just because you think it should. You know better than that, so you add a bit of special code to verify your assumptions. And if it turns out you were wrong, it’ll raise an exception that you almost certainly have nothing in place to catch at any level before the global exception handler for your app.

Sound familiar? It should. You probably do it all the time. It’s an as-cast.
Continue reading ‘As-sertion casting’ »