- 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
Ok, this definitely falls in the category of bad-and-I-almost-guarantee-not-fun code. Sort of a warning: "Abandon all hope, ye who enter here."
Admin
The "(int)0.5 + radius" has a precedence bug that makes it a noop, but it isn't as dumb as it looks. Using (int)(0.5 + x) is a quick & easy way to get proper rounding behavior of positive (!) floating point values. If the code is in C, note that there are portability issues with functions like round() and rint(), and the above code might actually be preferred in some environments.
Admin
I'm reminded of the "infinite defects methodology" mentioned in Joel's tale of Microsoftian woe (see test item #5). Maybe whoever wrote this was on a death march, in a situation where there's heavy time pressure to check in code, and evaluating whether it works properly or not will just wait until the next phase in the project? If so, the code WTF is simply a symptom of the management/planning WTF that is The Real WTF™.
What, are they using the ancient Babylonian calendar, or something?
Oh yeah: fist!
Admin
"<font id="Michael">Good evening and welcome to another edition of 'Prejudice' - the show that gives you a chance to have a go at Wops, Krauts, Nigs, Eyeties, Gippos, Bubbles, Froggies, Chinks, Yidds, Jocks, Polacks, Paddies and Dagoes."</font>
Admin
Admin
Is it bad that I understood this instantly?
I actually did benchmarks for methods of combining two hashes in perl, and this method seems to be significantly faster than any others I tried. I think it looks a lot nicer without all those optional braces, tho:
@$gst{keys %$rec} = values %$rec;
And as for the comment... well, I'm gonna have to confess to using similar comments myself. Code can be evil-genious-y without being inappropriate for serious projects, IMO.
Admin
It's the Egyptian calendar as far as I know. (Yes, those piramid-building, beer-drinking weasels.:))
Admin
That's an artifact of the financial world.
And before anyone shoots me down, my source is Wikipedia, which is flawless and infallible. So there.
Admin
Looks like the "poor man's conditional breakpoint" again.
Any btw, I really like the earlier post time of the wtf. Reading it after lunch is great!
Admin
Admin
But he didn't put in the parentheses, and therefore, he made it onto WTF.
Admin
360-day calendar is used for a reason. Try to estimate the value of December call option for your favourite company using only your HP-12C calculator, given the fact that options expire at third Friday of every month.
Admin
There's nothing strange about this. it's common especially in some European countries banking system that a year has always exactly 260 days, a month always has 30 days. It's for calculating daily and yearly interest and stuff like that. Interesting, isn't it?
Admin
You've never used a GOTO statement before, have you? Think of it as the following:
Hope be with ye,
Cyan
captcha: tango - it takes two
Admin
Looks like this is from Javascript.
radius is some string and to get this value into an integer, well one hack was to add 0 to it.
Not elegant though.
Yea, from the financial world. Some ( nine, I think ) special ways for calculating interest. The more complex ways to calculate interest, give more benefits to the account holder.
Admin
That makes it a bug, not a WTF. The Real WTF is that neither the submitter nor the editor apparently understood the coder's intent.
Admin
Note: If b=false then would come out of that equation equal to true. The if... then is completley unneeded. Now what the poor guy was meaning to do is a whole different matter.
Admin
How old are some of these?
I'll step up and tell you that I cut my programming teeth on BASIC with line numbers. I'll also offer a guess as to how this ended up in the wild.
Depending on the machine and the BASIC variant, jumping over a line of code might be easier than 'commenting it out.' Some of those old built-in editors were onery, and it was much easier to use a GOTO to jump over a suspect line. (Line 1002 might have just been something like 1002 REM - DEBUGGING.) Then, after that line was checked, the programmer, again avoiding the editor, just changed line 1002 to jump to the original line. Why not 1010? Hey, this is a weak enough explanation anyway...
Admin
I've seen this one alot - like some other posters - it's a good way to round up (if you get the parens right...)
at first i thought... could this be some way of encoding a truth table? then i thought... WTF? b should always = b. Although i had to add the line k=k; into a program once to make it work... so maybe a funky compiler issue...
I can see this happening. The guy came up with a nice line of code that no mere hack would conjure... he was proud of it. and the comment means: don't change this unless you know what you are doing.
Admin
Actually, operator precedence would cause the 0.5 to be cast to an int, yielding a value of 0, which would then be added to radius.
Admin
Actually, operator precedence would cause the 0.5 to be cast to an int, yielding a value of 0, which would then be added to radius.
Admin
No, it used the assignment (=) and not the comparison (==)
b=b returns b. If b is false, the if doesn't execute and returns b (which is false).
This is language dependent of course but it looks C stylee to me.
Admin
Crap, it isn't C style is it? I think I have code blindness.
Rich
Admin
But it isn't this time! It's like a poor-man's conditional breakpoint that's broken! It will always fire, so it's not any more helpful than just 'b = true'.
Or maybe it used to be the real poor man's conditional breakpoint, and has gradually morphed...
(Or maybe it's as Rich says and in a language where = in an if still does assignment. But given that it looks like VB... I'm betting not)
Admin
I believe you are right. There are some nasty rounding errors that crop up in JavaScript arithmetic. Something to do with hexadecimal representation of floats.
Of course, at the same time, I don't think you can last like that in JavaScript. Anyway, I suppose the same rounding issues could occur in other languages.
Admin
Think of it as a Choose Your Own Adventure (tm) book:
.... Bob is about to fire his gun!
If you decide to dodge left, turn to page 1000.
If you decide to dodge right, turn to page 1050.
Page 1000
Bob fires his gun just as you dodge left.
Turn to page 1002 to find out if the bullet his you!
Page 1002
The bullet hits you!!
Turn to page 1010 to find out if you live or die!
Page 1010
Whoops, the bullet killed you.
The End.
Admin
We need more information to conclude that something is wrong.
For example, we don't know what the data type of b is: if b can be "null", then (except in a few strange Microsoft worlds), b = b will return false.
To even claim this much, I'm making assumptions about the nature of "=". Like I said at the beginning, we need more information before we can start laughing at this one.
Admin
Crap, I messed up the sequence!
captcha: whiskey. :D
Admin
no, no i'm pretty sure we can laugh at this now...
Admin
Admin
Then in my opinion it's still a WTF because the datatype is wrong.
Admin
Actually, there ARE a lot of 360 day year apps.
Steve
Admin
Wrong, it would come out false. The value of an assignment statement is equal to the value that was assigned. Thus, (b = false) evaluates to false, and b would not come out true because that part would be skipped.
Admin
I wanna see the rest of the constructor calls in the Stereotype Factory!!!!
Admin
Floating-point math is inexact on nearly every architecture due to the binary representation. It looks like C code to me though, and it looks like the programmer is trying to round off a float, not just cast it. However, some parentheses were forgotten. I think the real WTF is that whoever sent that in thinks it's a WTF.
Admin
I doubt it's characters - the name of the struct (disk_request) suggests that it's pretty low-level code.
Also, no-one seems to have commented on the bizarreness of
. You guys are going soft. :-(Admin
Also know as "spaghetti code"
{no offense intended to the linguini-eating mobsters}
Admin
I wrote the "# muhahahaha" line two companies ago, and like "Irrelevant" the first thing I thought when I saw it again was that it had unnecessary braces, and in my defense, Bob probably made me keep them. I believe at the time it replaced a much larger and clunkier chunk of code, hence the evil laughter from my volcanic headquarters. Naturally I know who P.C. is and I'll be dropping him a line. Good times, good times :).
Admin
Well quite. As perl code goes this is rather sane, readable even with all the curlies, I've seen & written far more evil code in the last ten years. The only WTF was why was this included?
As for the comment I write similar things all the time, and I now several perl mongers with far more evil commenting schemes.
Captcha: STFU (oh if I must.. ;-)
Admin
What language are you assuming it is?
It looks like Visual Basic to me, which means that b=b is a comparison, not assignment.
Admin
"Is it bad that I understood this instantly?" It's only bad, since that code isn't legal perl code. You can assign to an array of hash keys that way, you just have to do something like "%bighash = (%hash1,%hash2);"
Admin
I agree, the Perl should be instantly grokkable to anyone who's done any serious programming with references in Perl5. I do think it's clearer without the braces, though. For even greater clarity, when performance wasn't at a premium I'd probably go with this less-efficient but (to me) easier to read version:
# merge %$rec into %$gst
%$gst = %$gst, %$rec;
Admin
Huh. Where'd my parentheses go? That should be this:
%$gst = (%$gst, %$rec);
Admin
We have clients that measure quarters in groups of {4 week, 4 week, 5 week}
4 quarters * 13 weeks = 52 weeks = 364 days.
Hence their calendar drifts at least 1 day a year, and 2 on leap years,
and every 6 years so so, we are required to make program changes to bring their calendar back in line
with the 365/366 day calendar.
Admin
Not necessarily. (Though it will act as if false for the "if")
mysql> select null=null;
+-----------+
| null=null |
+-----------+
| NULL |
+-----------+
1 row in set (0.00 sec)
Captcha: null (amusingly enough)
Admin
Floating point math is inexact on all architectures (provided you use fixed-length mantissa and exponent), because it was designed that way. It's just a quick, memory-efficiant but inaccurate way to represent fractions using a logarithmic scale.
Admin
I was thinking this might be an automated translation from FORTRAN, which for some dumb reason assumed every GOTO was a computed GOTO.
Admin
Most of you are assuming that this one is written in a language that uses = as both the comparison operator and assignment operator. If that is not the case, then this is really just the same as setting b = true if b has a value that evaluates to true (like 1).
Admin
Admin
It doesn't look C stylee to me... the conditional isn't in parenthesese (parenthasees? parenthesees? parentheseas? er..curved braces.), and the keyword "then" is used.