Comment On A Real Brazil Nut

Code snippets know no geographic boundaries. [expand full text]
« PrevPage 1 | Page 2Next »

Re: A Real Brazil Nut

2007-02-20 09:03 • by Will (unregistered)
Is this possibly real?

Anyone who knows enough about coding to use conditionals will surely know that that is bad code.

Re: A Real Brazil Nut

2007-02-20 09:10 • by SmashAndGrab (unregistered)
121441 in reply to 121440
Because


If MyValue >= 0 and MyValue <= 7 Then &MyValueDes = MyValueDes

Doesnt look like a pyramid when you turn it on it's side.

Re: A Real Brazil Nut

2007-02-20 09:11 • by SomebodyElse
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

Re: A Real Brazil Nut

2007-02-20 09:11 • by Bill (unregistered)
121443 in reply to 121440
Will:
Is this possibly real?

Anyone who knows enough about coding to use conditionals will surely know that that is bad code.


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.

Re: A Real Brazil Nut

2007-02-20 09:13 • by Trained.Monkey (unregistered)
maybe he did not know about AND operator :-)

Re: A Real Brazil Nut

2007-02-20 09:16 • by TB (unregistered)
Maybe he gets paid by the line!

Re: A Real Brazil Nut

2007-02-20 09:22 • by Al (unregistered)
121446 in reply to 121440
Will:
Is this possibly real?

Anyone who knows enough about coding to use conditionals will surely know that that is bad code.


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

Re: A Real Brazil Nut

2007-02-20 09:23 • by Adrian (unregistered)
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..

Re: A Real Brazil Nut

2007-02-20 09:35 • by Laurent (unregistered)
Hahaha this figure looks like a fish or an arrow.. It effectively reminds me of pitfall post ;)

Funny ;)

Re: A Real Brazil Nut

2007-02-20 09:38 • by Ancient_Hacker
121452 in reply to 121440
Can somebody exlain what this line does:

&MyValueDes = MyValueDes


looks like a no-op to my un-vb-trained eye.


Re: A Real Brazil Nut

2007-02-20 09:41 • by Dim (unregistered)
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.

Re: A Real Brazil Nut

2007-02-20 09:42 • by Nicolas V. (unregistered)
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.

Re: A Real Brazil Nut

2007-02-20 09:48 • by ssprencel
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'.

Re: A Real Brazil Nut

2007-02-20 09:49 • by S (unregistered)
121456 in reply to 121440
Will:
Is this possibly real?

Anyone who knows enough about coding to use conditionals will surely know that that is bad code.


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'...

Re: A Real Brazil Nut

2007-02-20 09:56 • by Chedabob (unregistered)
Hold on a minute, doesnt everything return the same result so

If (myvalue <7)
&MyValueDes = MyValue Des


would suffice?

Re: A Real Brazil Nut

2007-02-20 09:57 • by noise (unregistered)
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 ) )

Re: A Real Brazil Nut

2007-02-20 10:06 • by akatherder
121463 in reply to 121458
Chedabob:
Hold on a minute, doesnt everything return the same result so

If (myvalue <7)
&MyValueDes = MyValue Des


would suffice?


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.

Re: A Real Brazil Nut

2007-02-20 10:12 • by mkb
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

Re: A Real Brazil Nut

2007-02-20 10:17 • by Volmarias
121465 in reply to 121440
Will:
Anyone who knows enough about coding to use conditionals will surely know that that is bad code.


*cough*

/me adds the obligatory link to the "poor performer and they don't know it" article...

Re: A Real Brazil Nut

2007-02-20 10:17 • by Aaron Isotton (unregistered)
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.

Re: A Real Brazil Nut

2007-02-20 10:18 • by GeneWitch
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

Re: A Real Brazil Nut

2007-02-20 10:37 • by ChrisH (unregistered)
This is surely generated code.

Re: A Real Brazil Nut

2007-02-20 10:37 • by Marcin (unregistered)
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.

Re: A Real Brazil Nut

2007-02-20 10:37 • by Marcin (unregistered)
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.

Re: A Real Brazil Nut

2007-02-20 10:38 • by Marcin (unregistered)
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.

Re: A Real Brazil Nut

2007-02-20 10:39 • by Marcin (unregistered)
The real wtf with the forum is that posts take a while to appear.

Re: A Real Brazil Nut

2007-02-20 10:40 • by Cratig
If this is real, then I reckon that the writer didn't even bother with indentation either.

Re: A Real Brazil Nut

2007-02-20 10:56 • by Trevel (unregistered)
121477 in reply to 121474
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.

Re: A Real Brazil Nut

2007-02-20 11:02 • by aaron (unregistered)
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!

Re: A Real Brazil Nut

2007-02-20 11:10 • by Romeo (unregistered)
C'mon... give the coder a rest... it's carnival here in Brazil today!

CAPTCHA: yummy - yep, carnival tastes like that!

Re: A Real Brazil Nut

2007-02-20 11:35 • by paint (unregistered)
121485 in reply to 121474
Cratig:
If this is real, then I reckon that the writer didn't even bother with indentation either.
VB does that for you.

Re: A Real Brazil Nut

2007-02-20 11:37 • by Gedoon (unregistered)
121486 in reply to 121479
aaron:
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!


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 ;)

Re: A Real Brazil Nut

2007-02-20 11:39 • by Tann San
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!

Re: A Real Brazil Nut

2007-02-20 12:05 • by AbbydonKrafts
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.

Re: A Real Brazil Nut

2007-02-20 12:27 • by Mike (unregistered)
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 :)

Re: A Real Brazil Nut

2007-02-20 12:52 • by IneX (unregistered)
hey, at least he/she used tabs!

Re: A Real Brazil Nut

2007-02-20 13:19 • by iMalc (unregistered)
121501 in reply to 121444
Trained.Monkey:
maybe he did not know about AND operator :-)

That's still no excuse for making it longer than:

If MyValue => 0
If MyValue <= 7
&MyValueDes = MyValueDes
End if
End if

Re: A Real Brazil Nut

2007-02-20 13:26 • by ContractorInLivingHell (unregistered)
I look at this and that song from the 80s comes to me: "Shoot that poison arrow through my heeeearrrrtttt!"

Re: A Real Brazil Nut

2007-02-20 14:34 • by Zylon
Pfft. Clearly he should have done it like this:

&MyValueDes = Switch(MyValue = 1, MyValueDes, MyValue = 2, MyValueDes, MyValue = 3, MyValueDes,
MyValue = 4, MyValueDes, MyValue = 5, MyValueDes, MyValue = 6, MyValueDes,
MyValue = 7, MyValueDes, True, &MyValueDes)

A simple one-liner, VB style!

Re: A Real Brazil Nut

2007-02-20 14:55 • by Anonymous Coward (unregistered)
121531 in reply to 121501
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.

Re: A Real Brazil Nut

2007-02-20 16:14 • by StressBomb (unregistered)
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) {
...
}

Re: A Real Brazil Nut

2007-02-20 16:16 • by Dena Earley (unregistered)
121555 in reply to 121442
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.

It's not VB. VB requires "Then" after the expression on the If line, and the type declaration character (if used) goes on the end, not the beginning.

OMG Pitfall!

2007-02-20 16:34 • by fennec
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!

Re: A Real Brazil Nut

2007-02-20 17:05 • by BennyBerk
It wouldn't surprise me if the following piece of Java/C code achieved the same thing:

;

Re: A Real Brazil Nut

2007-02-20 17:58 • by foxyshadis
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.

Re: A Real Brazil Nut

2007-02-20 19:22 • by ChiefCrazyTalk (unregistered)
121584 in reply to 121443
Bill:
Will:
Is this possibly real?

Anyone who knows enough about coding to use conditionals will surely know that that is bad code.


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.


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.

Re: A Real Brazil Nut

2007-02-20 19:25 • by Canumbler (unregistered)
if((myVal - ((int)myVal) == 0) && (myVal != 0) && (myVal <= 7))
myValuedes = myValuedes;

captcha:darwin - if only...

Re: A Real Brazil Nut

2007-02-20 21:25 • by icelava
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

Re: A Real Brazil Nut

2007-02-20 22:00 • by Earl Colby Pottinger (unregistered)
121596 in reply to 121501
iMalc:
Trained.Monkey:
maybe he did not know about AND operator :-)

That's still no excuse for making it longer than:

If MyValue => 0
If MyValue <= 7
&MyValueDes = MyValueDes
End if
End if


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.

Re: A Real Brazil Nut

2007-02-20 22:19 • by BillyBob (unregistered)
121598 in reply to 121494
Mike:
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 :)


It's not C, that's enough to draw the conclusion that the language sucks ;-)
« PrevPage 1 | Page 2Next »

Add Comment