- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Wow.... why does this happen so often?
Admin
That piece code is awesome!
Addendum (2010-07-14 09:58): I see Mark B. fixed his typo. Oh well.
Admin
Maybe the friend doesn't like the exclamation mark in code? It's not easy to make this code shorter and not use an exclamation mark or question mark.
Reminds me of some code I saw once, which compared whether a certain integer was greater than 4 and less than 6.
Admin
if (value == false) { return true; } else { return false; }
is shorter and doesn't include !
Admin
Admin
Admin
It pains me to think that people like this are out there coding right now. Probably adding a few helper methods like IsIntEqualToOne(int i) and IsStringEqualToFudge(string possiblyFudge).
Admin
Big bad boolean blunder built by belligerent baffoon.
Alliteration FTW
Admin
At least
was initialized.Admin
At least they're using descriptive names and parameters. Even better: int2(int x) {return x == 1;}
Admin
public boolean isBooleanFalse(boolean value) { boolean response = true; if (value == true) { response = false; } return response; }
Admin
Reading is fundamental.
Admin
Admin
Admin
we needed this, i stole it
Admin
Where is its counterpart, isBooleanTrue() ?!?
(Do Code-Reviews, and you would catch these omissions)
Also, maybe somebody else there has already written isBooleanFalse(), and Brian's friend is reinventing the wheel. __ /hg
Admin
Yes bulletproofed. As long as no-one passes a null of course.
Admin
return value ^ true
is also shorter and doesn't contain !
Admin
I can imagine calls to that function might look something like this:
Admin
To me, this code looks like Java. And Java distinguishes between primitive types and objects. boolean (lowercase) is a primitive type, where Boolean (uppercase) is an object. Objects can be null, primitives cannot. The parameter is declared boolean (the primitive type), therefore no null value possible there.
Admin
Obviously you're not an auto-boxer.
Admin
So - if that checks if a boolean is false, and returns a boolean - should i use this function to check if this function returns a false boolean?
Its a never ending coding loop!!!!!!!!!!!!!
Dan
www.3xg.co.uk
Admin
Admin
I call bullshit! There's no friggin' way that someone smart enough to land a job could possibly be that fucked up.
Admin
Weak. We can do better.
Admin
Admin
Obviously, the correct way of doing this would be to replace this function with a call to a web service that submits the boolean value to a MS SQL Server 2008 via stored procedure. The database would then return the correct value by means of a VarBinary(Max) value of a JPEG image of a scanned Polaroid photo of the word 'True' or 'False' written on different colored index cards photographed on a wooden table.
... or just not use the function in the first place.
Admin
Defensive programming.
Admin
My senior developer coworker once asked me what I meant when I was refering to "boolean"... and I've already seen this kind of crap in his code (but as he's a C# developer he uses "bool" and never asked himself where does this 4 letters word comes from.)
Admin
It's funny to watch people go back and forth between "strong typing seems to help the compiler find my errors" and "strong typing requires me to do these annoying casts". The result is often pseudo dynamic code in a strong typed language.
These people need to read an article in a programming journal at least once per decade. Or maybe even go to school.
Admin
Did you by chance arrange it so that his genetic material no longer has any change of propagating through the gene pool?
Admin
Admin
FTFY
Admin
I love this site...
Admin
Admin
return !(false & !!!x)
Admin
oops!
return !(false & !!!value)
Admin
There you go, much better (and more complete):
public boolean isBooleanFalse(boolean value) { return !isBooleanTrue(value); }
public boolean isBooleanTrue(boolean value) { return !isBooleanFalse(value); }
Admin
The great thing about this is that it can be re-used to write isBooleanTrue...
Or, to keep the style consistent
Admin
No, no, no. The proper response is "Plz send teh codez"
Admin
You forgot to use IoC
Admin
Admin
And obviously you don't have the slightest clue how auto-boxing works. Well, auto unboxing since that's the only thing that would be affected here.
In Java, even if you have a Boolean that needs to be auto unboxed into a boolean, it will happen in client code before the call to isBooleanFalse. There is positively NOTHING the library function could do, or should do, to change that.
Admin
You're very lucky to work in such a competent team.
Admin
That depends on the language. If it requires initialization before use, then initializing it to a potentially wrong value is bad. If it does not require initializing, then initializing to a potentially right valid value is OK (though initializing to an invalid value like null is better, if you have the option).
Anyway, this example code isn't over-engineering, and isn't making anything more bullet-proof. It's just a very verbose way to implement the not operator.
Admin
Now that is over-engineering!
captcha: jumentum - momentum initialized by a jump.
Admin
See?
Admin
This is actually quite common in embedded systems where exclamation points and question marks have been removed to produce a reduced character set.
Admin
There, I think that just about covers it.
Admin
The compiler converts auto unboxing with a call to .booleanValue(). This would produce a runtime NullPointerException. By using a primitive as an argument, you guarantee that it will not be null. By using a primitive as a return type, you declare the method will not return null.
I've seen similar code which takes a Boolean as a parameter and returns a boolean just to avoid dealing with NPEs. In such code, null is treated as false.