- 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
meow is the meow meow
yep
Admin
These comments are useful. The original programmers realized how hard it would be to figure out which closing brace was for which conditional.
Admin
Bah, it makes total sense, they visually created a staircase, and the less likely the condition is, the steeper the slope - brillant!
Admin
// Forth // Thrid // Sekond // Frist!
Admin
Looks like they were using the Waterfall model.
Admin
I guess a switch statement was too much trouble...
Admin
Seems like it would make it easy to use find on page? I put in similar comments like // end $someconditional
Admin
This is very much common scenario for all legacy code. It is intentional on part of author and further succession of developers is also required mandatory to follow same pattern.
Admin
This ain't much uncomon scenario for scarecrow code. It is intent on part of author and further massage of programer is also required mandatory to massage same patern.
Admin
Or you could just not update the comments at all (I have a feeling that updating comments weren't a priority with these programmers), and just let those comments rot away, forever referring to incorrect line numbers.
At least with your style of comment you can mentally tell which code block is ending without resorting to multiple keyboard presses and mouse clicks.
Admin
I ain't be massaging multiple keyboards.
Admin
I worked on a program like this once. Around 50 levels of nested IF; nested so deeply that, from time to time, the authors were "out-denting" the code, to keep it from getting indented too much.
It took weeks to unravel that mess.
Admin
Admin
I'm struggling to picture the top half of this code. else if statements don't lead to multiple close brackets.
Admin
it's a gust front in code, leading to a storm of uncontrollable random numbers.
Admin
TRWTF is the invalid octal number at the end. If you're going to write bad code, at least write syntactically correct comments!
Admin
I can think of about 3 different ways to write that depending on what the actual necessity of it was... switch, loops, ||...
Should I consider myself lucky that I have never needed to solve a problem with 26 nested if statements?
Admin
It's probably nested if statements.
Admin
It's quite beautiful actually
Admin
The best part of those closing braces is that they form a (nearly) perfect curve. It's (almost) pleasing to the eye.
CAPTCHA: laoreet - the next Pokemon!
Admin
Admin
Admin
Context of this sucks, does the comment above at if block 15 say what the code is for/does?
Even then, shouldn't you be happy they added those? Yeah all the if blocks suck but at least you have a map.
Admin
They probably didn´t have a switch statement at that time.
Admin
At any rate, if someone decides to add another nested if-block somewhere in the middle, then they'll be stuck with updating all the numbers inside the new one.
Or not. They could just put a new number (greater than the others) and allow the nested blocks to simply degrade into no particular order.
Admin
Commenting close brackets can be a good idea in some cases. If you do so, then indicate what sort of block you are closing. The comment is supposed to help not confuse even further. And such comments are mostly useful at the end of a long block.
Admin
I weep for all you poor starving children, who don't have vi and therefore can't automatically hop to the matching beginning or end brace with just two keystrokes.
Admin
if (irish_girl) { if (paula) { if (!frist) { WTF WTF WTF WTF WTF WTF WTF } // endif !frist } // endif paula } // endif irish_girl
If your nested blocks gets longer than a page (I know the shouldn't, but sometimes...) this is actually a good way to make the code more readable.
Admin
You see? This is why java needs case switch statements for strings!
Admin
They do if you're anal about bracing everything:
Technically,
is a "one-line" unbraced else.Admin
I want to see the code around it. What is it supposed to do? The number 26 makes me think it has something to do with alphabetizing, but the "09" at the bottom REALLY makes me wonder.
Admin
Now that's a bad case of else-if-heimer.
Admin
This is all nonsense. The following is perfectly valid C:
OK, so it's not perfectly useful C, but that's really a triviality.
Admin
I think the story's title, "Unconditionally Useless", is intended as a predictive description of the majority of the comments...
Admin
OK, just to point out the obvious here:
Commenting close brackets helps. Esp if the function is long. Yes the en-brackened code should not span a hundred lines, but we all know that happens, and if you at least made some decent comments, refactoring your mess becomes easier.
But, as usual, these comments should be a direct translation of the code they are commenting. ( i = 1; //set i to one)
if you do something like this
if (i > 5) // explanation of why the first five are special { //long messy code here } else // we are no longer in the special case { //more messy code here }
You might still have written crap code, but at least cleanable crap. Big difference.
Admin
The good thing is, though, that we don't need three years to master a 100% unintuitive writing system to write code faster than in normal IDEs.
And besides, every useful IDE can do what you just described in few keystrokes.
Admin
It's not an unsolvable problem, is it?
That's the beauty of this approach. If used correctly, you will never run out of numbers (in the correct order) for your blocks.
Admin
In that case, I suggest octal:
captcha: ACSI - any strict subset of ASCII, jumbled (such as EBC-DIC).
Admin
An indentation level of (at least) 19? Refactor it from orbit, it's the only way to be sure.
Admin
It looks like a clumsy fudge to compensate for the bad tooling of the day.
Admin
It reminds you how many more braces you need to close.
I came across bunches of nested-ifs when writing in C and you have to check the return value of every function call you make. Not sure it came to as many as 26 but certainly can get to 5 or 6.
At each stage though the else would handle what failed and you would possibly need to clean-up the last thing that was properly allocated (the hidden "finally") after the if..else block.
C++ is so much nicer for this.
Admin
Maybe it was the frist version of this earlier WTF.
Admin
Right. Who's for just ripping it out and seeing what breaks? Anyone? Just me then?
I'd say a refactoring is in order here.
Admin
Admin
Have pity!
Admin
I'm waiting for the editor that takes no keystrokes to do anything. Whoever is supposed to be producing it is certainly taking his time, and I wish he'd get a move on - I have stuff to get done.
Admin
Degrading one step further down to PHP in every new release...
Admin
String.toLowerCase() uses the rules of the default locale. So set default locale to "tr TR" and test with:
Admin
This cries for the obligatory XKCD.
Admin