• Will (unregistered)

    Is this possibly real?

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

  • SmashAndGrab (unregistered) in reply to Will

    Because

    If MyValue >= 0 and MyValue <= 7 Then &MyValueDes = MyValueDes Doesnt look like a pyramid when you turn it on it's side.
  • (cs)

    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

  • Bill (unregistered) in reply to Will
    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.

  • Trained.Monkey (unregistered)

    maybe he did not know about AND operator :-)

  • TB (unregistered)

    Maybe he gets paid by the line!

  • Al (unregistered) in reply to Will
    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

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

  • Laurent (unregistered)

    Hahaha this figure looks like a fish or an arrow.. It effectively reminds me of pitfall post ;)

    Funny ;)

  • (cs) in reply to Will

    Can somebody exlain what this line does:

      &MyValueDes = MyValueDes
    

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

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

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

  • (cs)

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

  • S (unregistered) in reply to Will
    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'...

  • Chedabob (unregistered)

    Hold on a minute, doesnt everything return the same result so

    If (myvalue <7) &MyValueDes = MyValue Des

    would suffice?

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

  • (cs) in reply to Chedabob
    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.

  • (cs)

    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

  • (cs) in reply to Will
    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...

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

  • (cs)

    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

  • ChrisH (unregistered)

    This is surely generated code.

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

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

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

  • Marcin (unregistered)

    The real wtf with the forum is that posts take a while to appear.

  • (cs)

    If this is real, then I reckon that the writer didn't even bother with indentation either.

  • Trevel (unregistered) in reply to Cratig

    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.

  • 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!

  • Romeo (unregistered)

    C'mon... give the coder a rest... it's carnival here in Brazil today!

    CAPTCHA: yummy - yep, carnival tastes like that!

  • paint (unregistered) in reply to Cratig
    Cratig:
    If this is real, then I reckon that the writer didn't even bother with indentation either.
    VB does that for you.
  • Gedoon (unregistered) in reply to aaron
    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 ;)

  • (cs)

    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!

  • (cs)

    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.

  • 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 :)

  • IneX (unregistered)

    hey, at least he/she used tabs!

  • iMalc (unregistered) in reply to Trained.Monkey
    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

  • ContractorInLivingHell (unregistered)

    I look at this and that song from the 80s comes to me: "Shoot that poison arrow through my heeeearrrrtttt!"

  • (cs)

    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!

  • Anonymous Coward (unregistered) in reply to iMalc

    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.

  • 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) { ... }

  • Dena Earley (unregistered) in reply to 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.
    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.
  • (cs)

    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!

  • (cs)

    It wouldn't surprise me if the following piece of Java/C code achieved the same thing:

    ;

  • (cs)

    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.

  • ChiefCrazyTalk (unregistered) in reply to Bill
    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.

  • Canumbler (unregistered)

    if((myVal - ((int)myVal) == 0) && (myVal != 0) && (myVal <= 7)) myValuedes = myValuedes;

    captcha:darwin - if only...

  • (cs)

    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

  • Earl Colby Pottinger (unregistered) in reply to iMalc
    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.

  • BillyBob (unregistered) in reply to Mike
    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 ;-)

Leave a comment on “A Real Brazil Nut”

Log In or post as a guest

Replying to comment #:

« Return to Article