CodeSOD: Counting on Switching

This post was originally published on this site

The Daily WTF

Frequent contributor Argle found some code written at his current company a “long time ago”, but unfortunately in a galaxy far too close to our own.

If rsRecordSetD1T3(“ItemState”)<>”N” then Select Case rsRecordSetD1T3(“ItemState”) Case “R”, “L” tally=tally+1 Case “B” tally=tally+2 Case “N” tally=tally+0 Case Else tally=tally+0 End Select … End If

We start with an If: only enter this branch if ItemState is definitely not equal to “N”. Then we enter a switch.

If ItemState is “R” or “L”, we add one to tally. If it’s “B”, we add two. If it’s “N”, we add zero, and wait, we need to pause here a moment.

First, we know it can’t possibly be “N”. We just checked that above. But then, we also… add zero. Which is effectively a no-op, at least in terms of its impact on program state.

And then, in a Case Else, e.g. for all other values,

To read the full article click on the 'post' link at the top.