CodeSOD: Never Don’t Stop Not Doing This

It's not nothing to never write confusing English. And it doesn't never influence the code that we write. Don't fail to look at this anti-pattern from today's un-named submitter.

If Not port Is Nothing Then portUnAvailable = False End If

If the port isn't nothing, then the port isn't unavailable. That's… not untrue. But it is surprisingly confusing when you're reading it in a larger block of code. And, of course, this would be simpler to express as a boolean operation:

portUnAvailable = port is Nothing

Then again, without context, that might be wrong- perhaps portUnAvailable gets set elsewhere and then changes only if Not port Is Nothing. But let's assume that's not how this works, because that hints at a bigger WTF.

Do never don't avoid this pattern in your own code or writing.

[Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.

This post originally appeared on The Daily WTF.

Leave a Reply

Your email address will not be published.