- 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
Is this possibly real?
Anyone who knows enough about coding to use conditionals will surely know that that is bad code.
Admin
Because
If MyValue >= 0 and MyValue <= 7 Then &MyValueDes = MyValueDes Doesnt look like a pyramid when you turn it on it's side.Admin
I haven't seeen code like this in a few years. I believe that is VB5 code, with the &var declarations. Of course, you could still use them thru VB6, but not many did.
~SE
Admin
It's a stub. I'd bet money on it.
I've seen these literally dozens of times over the years as I've inherited code. They know that those are the values to be checked, but don't know the logic yet ("you go code, I'll get the requirements"), so they code the structure to return "Sanity check" values until they have the real business logic.
Sadly, I've seen these stubs make it to production far too often as well.
Admin
maybe he did not know about AND operator :-)
Admin
Maybe he gets paid by the line!
Admin
It's bad code, but made even worse by the fact that the person hadn't heard of 'ElseIf' ... which would have made it slightly less 'pyramid' like.
Al
Admin
Yes..he gets paid by the line and probably its was all he had to do that day....write a line for a new condition...:) If he will make is with AND its will be to simple to change only one char...so ...at list he is pretending to do something..
Admin
Hahaha this figure looks like a fish or an arrow.. It effectively reminds me of pitfall post ;)
Funny ;)
Admin
Can somebody exlain what this line does:
looks like a no-op to my un-vb-trained eye.
Admin
I'd hate to see any other conditions in this code. If he/she couldn't abbreviate a simple range condition, think of the mess elsewhere.
This must be one of those train-wreck programmers: the further you read down the code, the more it feels like a train wreck in slow motion.
Admin
We have a designer who fancied himself a programmer who built an entire Web application like this.
His stuff worked but was full of bugs.
His PHP was very very basic and he never learned about the existence of SWITCH (which is a very universal mnemonic).
When we tried to explain upper-management that his application and code sucked, they just did not care, that's the issue, but you've got to live with it.
Admin
This isn't Visual Basic. All 'If' condition statements must end with the 'Then' key word. Also, 'Endif' would not compile. It would have to say 'End If'.
Admin
Yes it could be real - I've seen worse in the past.
15 nested if statements with a comment that read something along the lines of 'Don't change this, it works but I don't know why'...
Admin
Hold on a minute, doesnt everything return the same result so
If (myvalue <7) &MyValueDes = MyValue Des
would suffice?
Admin
oh... that's easy... tho its hard to tell without comments.
it's for debugging a multithreaded operation. the author has noticed the variable in question has been changing randomly, so the author runs this in a tight loop sets a few breakpoints, and.... eventually... finds who's changing it to what and when.
( i'm joking ( i hope ) )
Admin
Maybe the coder only wanted whole numbers between 0 and 7. That would allow negative numbers (-1) and non-whole number (6.5, 1.33333).
The code could be simplified with a bunch of OR's but that still makes for one really long messy line. Anything other than that and you're changing the purpose of the code we are given.
Admin
This is what happens when your coding guidelines forbid early returns! I had to work on code that looked like this in a C++ environment where continue was outlawed, multiple returns were outlawed, break was evil outside of a switch statement, and exceptions (caught or thrown) killed the Microsoft executable our DLL was inside. GRRRRR
Admin
cough
/me adds the obligatory link to the "poor performer and they don't know it" article...
Admin
You just don't understand the code because that guy is a Real Programmer. That's an optimization, it's called "condition unrolling".
On an 8-core machine all the checks could be done in parallel, thus only requiring one instruction (equal) before knowing which branch to take, which is obviously faster than the three instructions it takes to do it the conventional way (greater, less, and). Also, it's more fun.
Admin
psuedo #1
trim(x) // rip decimal off (i forget the function todo this) OR x = <int>(x) // force a cast to int. assert(x<=7 && x=>0) varY = x
Pseudo #2 What the other poster said
if (x => 0 && x <= 7) then varY = x else throw(FILE_NOT_FOUND) fi
But i like the pyramid. And ya, i love my WTF code. :-D
Admin
This is surely generated code.
Admin
The real WTF here is that the logical and clear indentation pattern is being criticised. The use of separate ifs simplifies instrumenting the code to discover which caller is passing in which constants.
Admin
The real WTF here is that the logical and clear indentation pattern is being criticised. The use of separate ifs simplifies instrumenting the code to discover which caller is passing in which constants.
Admin
The real WTF here is that the logical and clear indentation pattern is being criticised. The use of separate ifs simplifies instrumenting the code to discover which caller is passing in which constants.
Admin
The real wtf with the forum is that posts take a while to appear.
Admin
If this is real, then I reckon that the writer didn't even bother with indentation either.
Admin
I've seen worse.
Take the same code and throw a
For (MyValue==0;MyValue<=7;MyValue++)
or whatever language equivalent around it and then you'll have REAL fun.
Admin
Ok... I'm really hoping that in the sample code, the assignment operator "=" wasn't REALLY being used as a conditional operator (usually "=="). This is just pseudocode, right?
captcha: quake yay!
Admin
C'mon... give the coder a rest... it's carnival here in Brazil today!
CAPTCHA: yummy - yep, carnival tastes like that!
Admin
Admin
It's VB or some other shit like that where a single = actually is the equals operator, not assignment. In C/C++/Java/Whatever you'd use == but this is not the case. But I do agree that that VB or C#.net or what the hell you call it is pseudo code, not a real programming language ;)
Admin
The real wtf is that the first "Else" is indented when it shouldn't be which obviously breaks the aesthetic flow for all the child if/else statements, shame on them!
Admin
WTF is up with people thinking C# is not a language? GD! It's virtually like Java (especially since they "stole" ideas from it). Drop it already! Sheesh...
And WOW.. I actually had that version of Pitfall on a 286 I owned years ago.
Admin
What's funny in these comments is the way some people dis the language when it's obvious that they don't even know what the language is :)
Admin
hey, at least he/she used tabs!
Admin
If MyValue => 0 If MyValue <= 7 &MyValueDes = MyValueDes End if End if
Admin
I look at this and that song from the 80s comes to me: "Shoot that poison arrow through my heeeearrrrtttt!"
Admin
Pfft. Clearly he should have done it like this:
A simple one-liner, VB style!
Admin
There is potentially a reason to do this (although I suspect the coder was just moronic). If you knew that it was VERY likely that MyValue is 0 (and vastly more likely that it was 1 than 2, etc) then this code is faster making two comparisons.
Admin
What an idiot, he should know better how to Properly and Professionally check if a number is in range!
array range = [0,1,2,3,4,5,6,7];
bool inRange = false;
for (int i = range[0]; i < range[range.length-1]; i++) { if (someVar == range[i]) { inRange = true; } }
if (!inRange) { ... }
Admin
Admin
OMG! It's text-mode Pitfall! I tried Googling that game a while back, only found the graphics-mode jungle-adventure-type game by the same name. This is awesome! Thanks a bundle!
Admin
It wouldn't surprise me if the following piece of Java/C code achieved the same thing:
;
Admin
He forgot to add Else &MyValueDes = FileNotFound End If at the very top of the pyramid. (Shut up it's still funny. >( )
As I was reading it, I thought the wtf was that he was setting the address to the variable. I still don't know what & signifies in this case (string concatenation, hexadecimal, and ???), but obviously I've been doing C too long...
It's sad that C, especially Win32, virtually enforces structures like this in order to keep from leaking memory and resources.
Admin
Best explanation of bad code. Ever.
Seriously, I'd bet you are right. Most of the code was make fun of on this site is taken out of context.
Admin
if((myVal - ((int)myVal) == 0) && (myVal != 0) && (myVal <= 7)) myValuedes = myValuedes;
captcha:darwin - if only...
Admin
the programmer was anticipating change. Who knows if the business would change their policies to remove the condition for 3 or 5.
he he he
Admin
Sorry as already pointed out in other examples you code will fail to work properly if MyValue has a non-integer value.
The original only did the assignment on integer values, yours does not.
Admin
It's not C, that's enough to draw the conclusion that the language sucks ;-)