- 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
LOL! Cool function!
Admin
Its true, the kid who wrote this graduated in the same class as me, we both got our BS. Its totally insane how many people get a BS in CS at my school who have no idea how to write code in java, or c, or both. This kid was one of those people.
For one of our classes our junior year we were asked to write a program that would, given a String polynomial parse that, and stick the values into a double array. The class was titled "Empirical methods in computer science". A week after the deadline of this project, the professor made a nice little excel table detailing the class performance. If i remember correctly, 55% of the people passed in code that DIDNT COMPILE. 25% had code that compiled but they didn’t pass 1/2 the test cases. only about 5 people wrote programs that actually worked. I was the only one to use regular expressions.
On the other hand, if these are the people who are going to be competing for jobs with me... i should have no problem finding work.
Admin
There is no bool, if you look closely you can see its not the bool that is true, it is you who is false :s
Admin
A few years agon, I worked with this PhD who was all up-in-arms about qsort and how it had some worst-case behavior so he wrote his own insertion sort, but that's another story.
I came across this wonder in a Whole Pile of his code:
<FONT face="Courier New" size=1>#define TRUE (1==1)</FONT>
<FONT face="Courier New" size=1>#define FALSE (!TRUE)</FONT>
<FONT face="Courier New" size=1>#define FlagOn(b,f) (((b)&(f))!=0?TRUE:FALSE)</FONT>
This fellow left the company after a while and went back to teaching Software Engineering at a local institution...
Admin
This reminds me of one I caught in a code review a few months ago...no joke...
if(someObject.someBooleanProperty.ToString() == "true")
Admin
I have seen similar code in xBASE. For some reason, many people can not get their heads around boolean. The xBASE equivalent is:
The iif() function evaluates the first (boolean) expression. If true, it returns the second expression, otherwise the third. (.t. is true and .f. is false.) The example is much better stated:
Sincerely,
Gene Wirchenko
Admin
In what reality do you live where job acquisition is based on merit? ;)
Admin
It looks perfect! I'm going to rewrite all my applications :)
(just kidding of course :P)
Admin
What language is this written in? And is it comparing references or values? The reason I ask is, in Java, even if someBooleanProperty was true, this would result in false, because references are compared. Could potentially be more of a WTF than it initally appeared.
Admin
hmmm ... and whats about a True Detector?
could be something like :
<FONT style="BACKGROUND-COLOR: #ffffff"><FONT color=#0000ff><FONT size=+0>public boolean</FONT> checkTrue(<FONT size=+0>Boolean</FONT> bool)
{
return !</FONT></FONT><FONT style="BACKGROUND-COLOR: #ffffff"><FONT color=#0000ff>checkFalse(bool);
}</FONT></FONT>
or even better ...
<FONT color=#0000ff><FONT size=+0>public boolean</FONT> checkTrue(<FONT size=+0>Boolean</FONT> bool)
{
return </FONT><FONT color=#0000ff>checkFalse(checkFalse(bool));
}</FONT>
hmmmm ... is this correct??? hmmm ... have to think about it ... *hrhrhr*
Admin
I would do something along the lines of:
<font size="3">if (foo == "" //if foo is empty,
|| foo == 0 //zero,
|| foo == null //null,
|| foo == false) { //or false
[do stuff]
}
if it were really that difficult to figure out.
</font>
Admin
No one asked for a solution.......chop!
Admin
We have
#define MINUS_ONE -1
in our flagship product :-)
Admin
When I was a TA for a programming course at my university, we had to deal with another variation of this frequently in the first couple of projects.
The course uses the SML language, which enforces strict type safety rules. Many students found these rules... unnerving, and would over-engineer large swaths of code in an attempt to "step around" the type-safety issues.
It got so bad that we had to start docking points on projects every time we saw code like this:
let result = if a then true else false
Note that because of the type-safety rules of the language, a is always guaranteed to be type bool...
Admin
System.Decimal.MinusOne
Admin
You work for Microsoft, then, I take it?
Admin
"Let him who is without sin cast the first stone ..."
I don't see anything wrong with this (if it works) ... Sure, this developer could have easily done a google search to find a better approach.But would that have made him/her a better developer. What I see from this code is someone who was thinking outside of the box. Which is a good sign that this person will eventually mature into solid developer.
I think the bad developers are those who COPY code without even taking the time to understand why it works ...
If we all just think back to when we were writing our first apps then we would better appreciate code like this. I wonder how many of those apps are still in production and are still being used?
Admin
I take it you are the original developer.
Seriously, the guy knew about the Boolean.booleanValue() method and yet rewrote it, including the usage of several calls to it. That is simply inexcusable and by no means a sign of a 'good thinker'. A 'good thinker' would be a guy who looked at his tools and used them.
Further, anyone who praises code for 'thinking outside the box' probably shouldn't be allowed near a computer.
Admin
This function is debug residue. They just forgot to delete it. My guess is it had something to do with an array, which in itself was built for debugging (probably an array that was a member function of another). We all leave debug residue from time to time, but usually the compiler is in your face about it. However, with it being in production i would assume it was in a sea of code to be overlooked to make it into production. This isn't much of a WTF to me. i've seen func(){return;} plenty of times in others code (but then again it is in beta stage, not in production).
<font color="Red">
</font>
Admin
How about the following solution?
public boolean checkTrue(Boolean bool)
{
return checkFalse(new Boolean(checkFalse(bool)));
}
<font size="+0"></font>
public boolean checkFalse(Boolean bool)
{
try
{
return !checkTrue(bool);
}
catch (StackOverflowError e)
{
return new Boolean(Boolean.FALSE.toString()).booleanValue();
}
}
Admin
I think this comment is almost as "Out-of-the-place" (couldn't be any more decent!) as the code itself.
What does it mean ?
Admin
Saw the following at my place..... (c++)
string FromBool(const bool x) {
if (true == x) {
return "true";
} else if (false == x) {
return "false";
} else {
throw InvalidDataException();
}
}
Well, it's certainly belt and braces.....
Admin
Wot, no localization options? :)
if (lang == "es")
{
return x ? "es verdad" : "no es verdad";
}
Admin
I was in a project once, writing C code, where the client insisted on having a #define for EVERY constant in the program. You weren't allowed to use literal numbers or strings anywhere.
So on April 1st my colleagues and I announced that we had made a header file to make life easier, and that we had already searched and replaced all the source code of the whole project to use the new header file.
I couldn't believe they fell for it and almost paniced when they saw the header file:
#define ONE 1
#define TWO 2
#define THREE 3
...
#define ONEHUNDREDANDTWENTYFOUR 124
...
(up to 1000)
Admin
That is ridiculous
Admin
<FONT face="Courier New" size=2>back in my college days, i used to meet a lot of gentlefolk who were out to get their cs degrees so they could afford to live in california and persue acting as a career.</FONT>
<FONT face="Courier New" size=2>"cs is just to pay the bills - it's not what i really want to do. i want to act!"</FONT>
Admin
> I was in a project once, writing C code, where the client insisted on having a
> #define for EVERY constant in the program. You weren't allowed to use literal
> numbers or strings anywhere.
> So on April 1st my colleagues and I announced that we had made a header file to
> make life easier, and that we had already searched and replaced all the source
> code of the whole project to use the new header file.
> I couldn't believe they fell for it and almost paniced when they saw the header file:
> #define ONE 1
> #define TWO 2
> #define THREE 3
> ...
> #define ONEHUNDREDANDTWENTYFOUR 124
> ...
> (up to 1000)
Funny. To be fair, I think what the person intended with the rule "no numbers" was to avoid magical number in the middle of the code. Then having a
#define MAX_USERS 163 /* some reason why it's 163 */
if (n > MAX_USERS) panic();
is somewhat better than a strange out of the blue
if (n > 163) panic();
especially if 163 is all over the place.
I take it you did not actually type the 1000 lines; how did you generate this joke file? I have an idea (hash of number and names (1-one, 2-two, ...., 70-seventy, 80-eghty, 90-ninety) I think after 100 it's just a matter of reusing the names available)... but maybe you came up with something clever.
Admin
naaaaaa me don't belive possible this oink?
Admin
Re: 163... of course
if (n > ONEHUNDREDSIXTYTHREE) panic();
is so much more alarming :)
Re: generating joke file
There is, of course, a Perl module for this
http://search.cpan.org/author/LHOWARD/Number-Spell-0.04/Spell.pm
Admin
well, if you name your var ONESIXTYTHREE it's stupid. now if you give it a meaningful name, then it's better; see the 163 vs. ONESIXTYTHREE vs. MAX_USERS: wich one carries the most useful information?
Admin
> There is, of course, a Perl module for this
> http://search.cpan.org/author/LHOWARD/Number-Spell-0.04/Spell.pm
what was I thinking, there's a Perl module for everything! Thanks for the info, I'll have a look at how it's done, I'm sure it's an interesting read.
Admin
It's C#. Not comparing references, but actually, that would return false because I forgot to capitalize the T in True.
Admin
I see the joke detector has been disabled.