CodeSOD: Accessible Booleans

For twenty years, Initech didn't have any sort of internal IT or anyone doing any sort of cohesive software purchasing or internal development strategy. Of course, as the company grew, they needed customized applications. With no official approach to doing this, the users did the best they could, using the developer tool installed on nearly every corporate Windows workstation: Microsoft Access.

That's when Kris got hired, along with a pile of other developers. The team had one simple mission: convert these Access applications into "real" applications.

Like pretty much every one of these projects, there were no requirements, beyond, "it should do the same thing as the existing application, but not be a fragile mess of overgrown code developed by people who didn't know what they were doing beyond just making it work". This meant that for a lot of the requirements analysis, Kris and the team needed to just trace through the code and try and figure out what it was doing.

By the standards of these kinds of applications, the code was better than average, but that still didn't mean it was fun reading. Since there was no source control, old versions of the code just lived on in comments, and that lead to some of these sorts of head scratchers:

'If rsEmplExp.EOF = False Then If rsEmplExp.EOF <> True Then rsEmplExp.MoveFirst

There seems to be an entire story here. The code used to check if EOF was false, but now it checks if EOF is not true. Was this change motivated by a bug? Did they do some weird dark magic to the resultset objects (implied by the rs prefix, so there's the one time in my life I've been happy to see Hungarian notation) that changed its behavior? Visual Basic does default to being loose with types, so there could be some coercion bug?

Or, and I think more likely, did someone get burned by type coercion once in the past, and thus learned "never check if it's false, always check if it's not true, because it could always be some other value like FILE_NOT_FOUND that's not true or false"? None of that information exists anymore, so we're left with just this one thing: we don't care if it's false, we only care if it's not true.

[Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today!

This post originally appeared on The Daily WTF.

Leave a Reply

Your email address will not be published.