Programmer mini-rant

Apr 05, 2009 15:11

It has been said by a smart programmer I know: "The more state you hold on to, the more bugs you will have to fix".

This generally seems to me like a sensible generalization, but today it really hits home.

I found an implementation of a linked list container that caches the current node that user code is querying. Getting the head of the list resets the "current" pointer, and getting the next one increments it. So, accessing nodes in the linked list looks like this:

node* pNode = pList->getFirst()
while (pNode)
{
    ...
    pNode = pList->getNext();
}

Of course, if any of this code should at any point iterate over the same linked list, it will result in an infinite loop.

And also of course, this code is embedded in our game's networking code, and the infinite loop would be triggered at unpredictable intervals under difficult to reproduce conditions, involving logic running in multiple threads. This is a bug that ate several frustrating hours of my life.

So, I'd like to send out a great big "fuck you" to whoever made this code. Fuck you. Fuck you very much. In both ears.
Previous post
Up