The Symmetry of Stupidity

Aug 1, 11:48 PM

Here’s a little method I came across in my travels recently that simply beggars belief. I’m not naming names or codebases, suffice to say it wasn’t in ours. It was too good not to share, so I’ve come out of early blogging retirement to post it:

java:
boolean areBooleansEqual(Boolean b1, Boolean b2) {    return b1 == Boolean.TRUE && b2 == Boolean.TRUE ||           b1 != Boolean.TRUE && b2 != Boolean.TRUE; }

I don’t even know where to begin to describe what’s wrong with this method. For your sake, I hope I don’t have to ;-) The icing on the cake was the accompanying “convenience” method:

java:
boolean areBooleansDifferent(Boolean b1, Boolean b2) {
        return !areBooleansEqual(b1, b2);
}

Truely inspired stuff.

The only convenience that came to mind when encountering these methods is the one down which I really wanted to flush this code. I’ll leave the last words to the innocent victims of these methods, B1 and B2.

Comments:

  1. Mmmmmm.

    I wonder what the unit tests for that look like! David    Aug 3, 02:16 AM    #
  2. There was something very similar to that on the DailyWTF the other day. Reckon it’s the same guy? — CeeCee    Aug 3, 02:41 AM    #

Blog roll

Codefeed
Madbean Matt
Vincent Massol
Codegargle
Mike Cannon-Brookes
Oliver Burn

Recent posts

Confessions of a Samurai Coder
JavaOne 2007 - random thoughts
Sneak Preview of Clover 2
Profanity in Software Considered Dangerous
20 Candles for CVS
Checking Pulse: CI Server initial impressions
Seethed Rivers on Our Sly Brain
FishEye plugin for JIRA
The Symmetry of Stupidity
Java Language Freakshow

Blatant plugs

Clover Clover & Clover.NET: Powerful code coverage for Java, C# and VB.NET
FishEye FishEye: datamining, browsing, monitoring for CVS, SVN, and Perforce
Crucible Crucible: efficient, distributed and process-neutral peer code review
Cenqua Cenqua: dedicated to the creation of practical, useful tools for software developers