hit counter
   
 

Random ramblings of a paranoid git
"The question is not if you are paranoid, it is if you are paranoid enough."


All | Security | Work | Wine & Dine | Leisure

   
   
20070305 Monday March 05, 2007
Stupid ways to check the condition of a boolean
Permalink | Comments [6] | 2007-03-05 12:58

I thought I had seen most things, but yesterday was given some code snippets (not produced at Sun) on how you can make things much harder than they really are.

Say that you want to check the condition of a Boolean. Most people would use

if (b) {
    // do stuff
}

But someone didn't think that was clear enough, so they used

if (b != false) {
    // do stuff
}

I though that was pretty bad, but then this masterpiece appeared

if (b.toString().length() < 5) {
    // do stuff
}

How on earth did they come up with that? The worst thing is that it is supposed to come from a real code base. I pity the ones who have to maintain it!

   
 
   
XML
« March 2007 »
SunMonTueWedThuFriSat
    
1
2
3
4
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
       
Today


Old entries


Bloggtoppen.se
OpenSolaris: Love at First Boot