- 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
"Nic" + "e."
Admin
Ok, the first theory is right out... 40+40+10-1 would have been much shorter. It's gotta be just a purely evil developer.
Admin
From looking at it I'd figure it's 61ZYX...CBA3
(Trying to type this out, I realised I do not know the alphabet backwards...)
I'd love to know what this was actually used/meant for though.
Admin
maybe the idea was to overflow the expression evaluator stack and overwrite some other variable or the return address?
I can think of several older compilers and interpreters that could be crashed in just this way.
Admin
WTF? Those brackets really aren't necessary
Admin
My method of measuring code quality is to ask myself if I would rather have herpes or maintain the code in question. In this case I would choose death by herpes.
Admin
My congratulations for the exquisitely named variable too :)
Admin
It might have been generated by the expansion of some plausible-looking set of macros. Why anyone would then decide to stick the preprocessed output into the code is another question, but people do do such things.
Admin
LISP would have been better suited to this problem. change patno -= ((((((((((((((((40+1)+1)+1)+1)+1)+1)+1)+1)+1)+1)+10)+1)+('Z'-'A'))+1)+1)+1);
to
(+(+(+(+(+(+(+(+(+(+(+(+(+(+(+(+(+ 40 1)1)1)1)1)1)1)1)1)1)1)10)1)(- Z A))1)1)1)
now it's readable, and there's one more pair of ()!
Admin
So I guess the WTF is that Kirk's company holds a Worst Line Competition. Look -- if you have a competition, someone is going to try to win.
Admin
Possible explanations:
We've all seen code that doesn't make sense when you look at the finished product. But no one would ever just sit down and write it that way. These things EVOLVE over time! It was previously just
patno -= (((((((((((((((40+1)+1)+1)+1)+1)+1)+1)+1)+1)+1)+10)+1)+('Z'-'A'))+1)+1);
but the last programmer was told to add one to the existing algorithm. And so on.
He was testing the optimizing compiler.
This is actually documentation. If you just code "patno -= 89" the next guy is going to wonder "Why 89? Where'd that come from?"
Computer Science teacher gave an F to anyone who didn't explicitly declare the order of evaluation.
Admin
I dunno. I watched some TV programme about a woman who died of Herpes Simplex 1 which is typically thought to be more annoying than anything else. The virus took over and shut down her liver, and it was quite a scary way to die.
You can just do the math in your head* and then refactor the line.
*What, you couldn't do that in your head?
Admin
Looks like this was written by somebody who missed calculus at school or was a bit too lazy. Instead of adding ones and tens and (z-a)s himself to the number that wasn't big enough, he just let the computer do it again and again.
Admin
Anyone else reckon it's output from the C preprocessor copy-pasted to production code?
Admin
i'd say the guy wanted to keep a trace of each time he had to increase the reducing value.
Admin
If the brackets were the only thing there that you found weren't necessary, I'm glad you don't work with me.
Admin
Admin
This code was written by the BDFH (Bastard Developer From Hell). And then he copyrighted it. Now, everybody has to pay if he wants to use his code.
That's the real WTF.
Admin
ORLY.
Admin
It makes me SICK the way our society just automatically turns to addition first as if that was the answer to every problem. Even assuming you are restricted to ones and zeros, you can still do it more efficiently with subtraction:
patno -= (((((((((((((((((100-1)-1)-1)-1)-1)-1)-1)-1)-1)-1)-1);
Kids these days! Grumble!
Admin
I can't quite believe this is pasted from preprocessor output. Even in macro language, I still can't imagine a situation that would call for all those + signs and brackets. If it was previously done with macros, it would still have looked horrible. Possibly even more horrible than this one, as it would have wrapped onto more lines...
Admin
Admin
What if the alphabet changes because some government decided to add new letters between A and Z ?
This code is future-proof.
CAPTCHA = eros
Admin
Admin
I have written some of those myself.
I bet each number is the width of a column in a columnar ascii report and the variable is the left margin of a subreport.
Regards from Germany
Franz-Leo
Admin
I saw once code from other party:
x += 1+1+1+1+1+1+1+1+1+1; y += 1+1+1+1+1+1+1+1+1+1+1+1; v = 1 + 1 + 1 + 1 + 1 + 1+1+1+1+1+1+1+1+1+1;
From what I know, their customer used an automatic test, checking that there are no "magic numbers" except from -1 to 5. So, they wrote a preprocessor...
Also, note different spacing in 1 + 1 + 1 + 1 + 1? Seems to be enum of another type!
Admin
Exactly! Who needs CVS?
Anyway, there's nothing wrong with writing out what should be a constant in an expression to make it's semantics clear. When I want to specify 5 minutes in ms, I do this:
final long ms = 5 * 60 * 1000;
not this:
final long ms = 300000;
So from reading the expression, it's pretty obvious what the semantics of that decrement are.
Admin
Or gasp you could use a comment! Then you can remove the assumption that the moron who will be reading/maintaining your code will see the "obvious".
final long ms = 300000; /* 5 minutes worth of milliseconds */
Admin
Unless of course the government then decided that Z looks much nicer when you put it after H. What this really needs is something to confirm the order of the alphabet, like a monster sized recursive 'if' block (if such a thing exists... and I can't think why it shouldn't).
Admin
A similar thing exists in the world of publications: In the first edition, they put all the numbers 2 4 6 8 10 9 7 5 3 1 onto the inner cover of the book, and remove a number each edition. The dev's probably trying to allow for that.
Admin
Admin
also, you can use a more descriptive name than "ms".
"5 * 60 * 1000" doesn't tell me that you are using milliseconds, it just tells me how you arrived at 300000.
final long TIME_IN_MILLISECONDS = 300000;
However, tells me everything I need to know.
Admin
Honestly.
Admin
Right! That's why you don't use magic numbers:
Define the constant PTANO_SUBTRACTION_FACTOR_1 and set it to octal 61. Then define the constant PATON_SUBTRACTION_FACTOR_2 and set it to hexadecimal 27. Make sure to make these global constants.
Then in your code, you just have to do
patno -= (PTANO_SUBTRACTION_FACTOR_1 + PATON_SUBTRACTION_FACTOR_2 + 1)\
Much clearer and more maintainable.
Admin
final long TIME_IN_MILLISECONDS = 5 * 60 * 1000; // 5 minutes in milliseconds
I know myself, and I would definitely omit or add an extra zero.
Admin
Admin
This already happened -- in the Greek alphabet, Z comes right before H. ("zeta" and "eta"). The Romans didn't use Z, so when they took the alphabet they replaced it with G. ("But wait", you say, "doesn't Greek have their own G ("gamma") right at the beginning?" To which I say, "Shut up unless you want me to write a 10 page essay on the history of the alphabet.") Later on, the Romans decided they wanted Z after all, so they just stuck it on at the end.
I think the Queen (I guess; it's her English, isn't it?) should tell us all to add Þ back to our alphabet, probably at the end, in which case you will not be laughing when all this programmer has to do is change "z - a" to "Þ - a".
("Þis programmer", I mean. And "I Þink Þe Queen", too, I guess.)
Admin
final long ms = 5 * 60 * 1000; /* 5 minutes worth of milliseconds */
which of course eventually got changed to
final long ms = 2 * 60 * 1000; /* 5 minutes worth of milliseconds */
as five minutes was too long a time for the purpose...
Admin
I agree, plus it'll be much easier to change later if you decide it should be 6 minutes.
Admin
I side with the Lisp guys. There is absolutely nothing wrong with the idea behind this code at all. The only two WTFs I see are the fact that it's not idempotent (for shame!) and that silly little semicolon at the end.
Admin
You might choose death by herpes; but do a google search for "tree man" for a look at what life with herpes looks like.
Admin
greetings from Iceland, where the thorn has been in use for a thousand years.
and wasn't it the ancient Irish who decided the alphabet should be in alphabetical order?
Admin
I actually do this all the time. Well, I don't put in the stupid comments, but I frequently write stuff like:
private static final long MARKET_CLOSE_IN_MILLISECONDS = 16 * 60 * 60 * 1000;
I guess it's a combination of me not wanting to do all that hard math myself and the (small) benefit of documenting exactly what the number is and why it has the value that it does. shrug
Admin
final long TIME_IN_MILLISECONDS = 5 * SECONDS_IN_MINUTE * MILLISECONDS_IN_SECOND;
You never know when someone will redefine the minute or millisecond.
Admin
Admin
The true WTF : patno is not reduced by 89 but by 150. Comments are wrong.
Admin
Maybe the author was trying to win the competition.
Admin
But how would I use that to increment by 11?
http://thedailywtf.com/Articles/If__0x2b__0x2b__Increments__0x2e__0x2e__0x2e_.aspx
Admin
Found worse: a javascript function to validate dates that was a series of nested ifs. 23 nesting. Evidently the writer did not like the "else if" construct.
And, oh, it was at least nicely formatted such as (syntax here may not be correct ;)
if(...) { } else { if (...) { } else { { if(...) { } else { if(...) { } else { // logical seriesc of checks ends here if(...) { } else { // and so on }
// and at the end... the closing paretheses } } } } } }
Admin
Or he should have written (44>>1)+1.
Captcha: damnum! How appropriate!