• Doo-doo Facial Hair (unregistered)

    I just got terrible Excel flashbacks of functions with endless =IF(something;"OK";IF(something;"LESS OK";IF(something;"HELP SOS";IF(something;"NO WAIT IT'S OK";IF(etc...

    And yes I know I was using Excel for something it was not really meant for but it was the only programming tool available (read: allowed) at the time.

  • ACK (unregistered)

    Damn, waited for years to write "First"... Went to check my else if branch code for bugs

  • Mr Magoo (unregistered)

    anything can be frist

  • William F (unregistered)

    TRWTF is the happy ending. Bad developer gets fired?

    Since this is in a safety critical industry, I feel better about airplanes and self driving cars already.

    CAPTCHA: ague - what I get from some of these stories

  • Michael P (unregistered)

    Some coding standards (like, say, the ones used for C++ on the US Joint Strike Fighter program) specifically require an if/else if chain to be terminated with either an "else" handler or a comment that explains why there is no else. That seems like good practice for any software with significant safety implications.

  • Tom (unregistered) in reply to Michael P
    Michael P:
    if/else if chain to be terminated with either an "else" handler or a comment that explains why there is no else
    How about
    else
    {
      alert('Universe asplode, select a different quantum fork');
    }
    Should be as good as the comment, if not better.
  • Rodnas (unregistered)

    // DO NOT make changes below this comment

    if (frist) { doLameFristComment(); } else if (!frist) { doAnythingCanHappenComment("And probably will!"); }

  • (cs)
    by creating code paths that did not assign these variables, he would cause unpredictable behavior depending on the prior values of the variables
    I don't understand this. Where are these new code paths? Is he talking about the possibility of some variable being undefined and therefore the IF and the ELSE IF both eval to false and neither block is executed?

    If so, TRWTF is using a loosely typed run-time language like JavaScript or PHP that allow undefined variables... especially in life-critical apps.

    Or, more likely, I've been mislead by Alex's brillant editing.

  • Anonymous Will (unregistered)

    I think he means about when some variable is supposed to be assigned a different value in the 2 branches.

  • Karl (unregistered) in reply to Tom
    Tom:
    alert('Universe asplode, select a different quantum fork');
    Oh, come on! We can do better than that.

    How about:

    alert("Logic inconsistency error detected! After you click OK, this instance of the simulation will be terminated. You should awake in a similar universe where this never happened. In most cases people report no recollection of this event.\n\nOh by the way, if you tell anyone else, it makes timeline reintegration much more difficult. So don't do that.");

  • long johnson (unregistered) in reply to LoremIpsumDolorSitAmet

    if patient.sick? && !patient.dead? heal patient else if !patient.sick? && !patient.dead? bury patient end

  • (cs)

    Wow the process worked.

  • Justsomedudette (unregistered) in reply to LoremIpsumDolorSitAmet
    LoremIpsumDolorSitAmet:
    If so, TRWTF is using a loosely typed run-time language like JavaScript or PHP that allow undefined variables... especially in life-critical apps.

    Or, more likely, I've been mislead by Alex's brillant editing.

    That would be Mark's brilliant editing, but please don't let accuracy or spelling ruin a perfectly snide comment.

  • Andrew (unregistered)

    You're right, anything could happen:

    a = 10
  • (cs) in reply to long johnson

    if patient.sick? && !patient.dead? heal patient else if !patient.sick? || patient.dead? if patient.dead? bury patient end end

    FTFY

  • Herwig (unregistered)
    if (a)
    {
      doSomething();
    }
    else if (!a)
    {
      doSomethingElse();
    }
    else
    {
      gotoTRWTF();
    }
    
  • (cs) in reply to Justsomedudette
    Justsomedudette:
    LoremIpsumDolorSitAmet:
    If so, TRWTF is using a loosely typed run-time language like JavaScript or PHP that allow undefined variables... especially in life-critical apps.

    Or, more likely, I've been mislead by Alex's brillant editing.

    That would be Mark's brilliant editing, but please don't let accuracy or spelling ruin a perfectly snide comment.
    Just because Mark submitted it doesn't mean it didn't get preprocessed by the almighty Alex! Or maybe Mark is his sockpuppet. Or maybe they're just as brillant as each other.

    PS. 'brillant' is not a typo; you must be new here!

  • Anonymous Cow (unregistered) in reply to LoremIpsumDolorSitAmet
    LoremIpsumDolorSitAmet:
    I don't understand this. Where are these new code paths? Is he talking about the possibility of some variable being undefined and therefore the IF and the ELSE IF both eval to false and neither block is executed?
    The issue that they're referring to would come up if they changed this:
    if(a > 10)
        printf("It's so big!");
    else
        printf("Not so big... :(");

    ...into this:

    if(a > 10)
        printf("It's so big!");
    else if(a < 10)
        printf("Not so big... :(");

    What happens if a is 10?

  • masseyis (unregistered) in reply to ACK
    ACK:
    Damn, waited for years to write "First"... *Went to check my else if branch code for bugs*

    Decades of experience in waiting to be frist

  • stinkiemcslimey (unregistered)

    if (a) { dowork(); } else if (!a) { domorework(); } else { return(FILE_NOT_FOUND); }

  • (cs) in reply to Anonymous Cow
    Anonymous Cow:
    LoremIpsumDolorSitAmet:
    I don't understand this. Where are these new code paths? Is he talking about the possibility of some variable being undefined and therefore the IF and the ELSE IF both eval to false and neither block is executed?
    The issue that they're referring to would come up if they changed this:
    if(a > 10)
        printf("It's so big!");
    else
        printf("Not so big... :(");

    ...into this:

    if(a > 10)
        printf("It's so big!");
    else if(a < 10)
        printf("Not so big... :(");

    What happens if a is 10?

    Yes, I understand how the terrible reverse-ifs resulted in "no fewer than ten bugs [being] created in the process".

    But that doesn't help me understand "creating code paths that did not assign these variables".

  • Mike (unregistered) in reply to long johnson

    shouldn't it be ... else if !patient.sick? || patient.dead? ...

  • Matthew (unregistered) in reply to LoremIpsumDolorSitAmet
    int foo;
    if (a > 10) {
        foo = 1;
    }
    else if (a < 10) {
        foo = 2;
    }
    printf("%d\n", foo); // Anything can happen
  • Ben Jammin (unregistered) in reply to Mike
    Mike:
    shouldn't it be ... else if !patient.sick? || patient.dead? ...
    ...no fewer than ten bugs were created in the process.
    Think about it... then giggle.
  • Kaso (unregistered) in reply to LoremIpsumDolorSitAmet
    char* ptr;
    
    if (something > 10) {
        ptr = BIG_BUFFER;
    } else if (something < 10) {
        ptr = SMALL_BUFFER;
    }
    
    memcpy(ptr, source, n); //error as the code path we followed did not assign ptr
    
  • Ben Jammin (unregistered) in reply to Mike
    Mike:
    shouldn't it be ... else if !patient.sick? || patient.dead? ...
    Plus, if you're not sick, hopefully being buried isn't the solution. Obviously, patient.sick? needs to be a tri-state boolean of true, false, and LIFE_NOT_FOUND.
  • Max (unregistered) in reply to LoremIpsumDolorSitAmet
    LoremIpsumDolorSitAmet:
    Anonymous Cow:
    LoremIpsumDolorSitAmet:
    I don't understand this. Where are these new code paths? Is he talking about the possibility of some variable being undefined and therefore the IF and the ELSE IF both eval to false and neither block is executed?
    The issue that they're referring to would come up if they changed this:
    if(a > 10)
        printf("It's so big!");
    else
        printf("Not so big... :(");

    ...into this:

    if(a > 10)
        printf("It's so big!");
    else if(a < 10)
        printf("Not so big... :(");

    What happens if a is 10?

    Yes, I understand how the terrible reverse-ifs resulted in "no fewer than ten bugs [being] created in the process".

    But that doesn't help me understand "creating code paths that did not assign these variables".

    An example in c++ would be:

    float x;

    if (x > 10) {

    }

    Defining x without initialising it to something (eg = 5.4f) means that it'll just contain the value of whatever was as that memory location. Could be any number, and results can change every time you run it.

  • Meta-commentator (unregistered)

    Seeing a marginal WTF, expects great reams of meta commentary on the post about the failure. Meta commentary does not exisist.

    So fail

  • Ben Jammin (unregistered) in reply to Max
    Max:
    LoremIpsumDolorSitAmet:
    ... Yes, I understand how the terrible reverse-ifs resulted in "no fewer than ten bugs [being] created in the process".

    But that doesn't help me understand "creating code paths that did not assign these variables".

    An example in c++ would be:

    float x;

    if (x > 10) {

    }

    Defining x without initialising it to something (eg = 5.4f) means that it'll just contain the value of whatever was as that memory location. Could be any number, and results can change every time you run it.

    Your example breaks an if/else as well as an if/else if. Refer to Kaso's.

  • jonkenson (unregistered) in reply to LoremIpsumDolorSitAmet

    I took that to mean that using this if - else if style would complicate things further up.

    "Doug was a go-getter. He made the effort to go through the rest of the module and bring all the if/else statements into his if/else if "pattern"."

    So essentially using this style, he introduced bugs higher up in the code that trickled down to cause a RWTF issue in this code.

  • Geoff (unregistered) in reply to LoremIpsumDolorSitAmet

    Because if you convert if .. else, into if .. else if !(cond) and you screw up the !(cond) part suddenly you have code where neither the if clause nor the else clause gets executed where it would have alsways been the case at least one would have been run before.

  • Buffoon (unregistered) in reply to LoremIpsumDolorSitAmet
    LoremIpsumDolorSitAmet:
    Anonymous Cow:
    LoremIpsumDolorSitAmet:
    I don't understand this. Where are these new code paths? Is he talking about the possibility of some variable being undefined and therefore the IF and the ELSE IF both eval to false and neither block is executed?
    The issue that they're referring to would come up if they changed this:
    if(a > 10)
        printf("It's so big!");
    else
        printf("Not so big... :(");

    ...into this:

    if(a > 10)
        printf("It's so big!");
    else if(a < 10)
        printf("Not so big... :(");

    What happens if a is 10?

    Yes, I understand how the terrible reverse-ifs resulted in "no fewer than ten bugs [being] created in the process".

    But that doesn't help me understand "creating code paths that did not assign these variables".

    int bar = 10;
    int foo;
    
    if(10 > bar)
       foo = 10;
    else if(10 < bar)
       variable = -10;
    

    Something like that spells it out enough for you?

  • Buffoon (unregistered) in reply to Buffoon
    Buffoon:
    LoremIpsumDolorSitAmet:
    Anonymous Cow:
    LoremIpsumDolorSitAmet:
    I don't understand this. Where are these new code paths? Is he talking about the possibility of some variable being undefined and therefore the IF and the ELSE IF both eval to false and neither block is executed?
    The issue that they're referring to would come up if they changed this:
    if(a > 10)
        printf("It's so big!");
    else
        printf("Not so big... :(");

    ...into this:

    if(a > 10)
        printf("It's so big!");
    else if(a < 10)
        printf("Not so big... :(");

    What happens if a is 10?

    Yes, I understand how the terrible reverse-ifs resulted in "no fewer than ten bugs [being] created in the process".

    But that doesn't help me understand "creating code paths that did not assign these variables".

    int bar = 10;
    int foo;
    
    if(10 > bar)
       foo = 10;
    else if(10 < bar)
       foo = -10;
    

    Something like that spells it out enough for you?

    Fix...

  • Fred (unregistered)

    Elseif can be useful. But it can ended in a mess

  • Abico (unregistered) in reply to LoremIpsumDolorSitAmet
    LoremIpsumDolorSitAmet:
    Justsomedudette:
    LoremIpsumDolorSitAmet:
    If so, TRWTF is using a loosely typed run-time language like JavaScript or PHP that allow undefined variables... especially in life-critical apps.

    Or, more likely, I've been mislead by Alex's brillant editing.

    That would be Mark's brilliant editing, but please don't let accuracy or spelling ruin a perfectly snide comment.
    Just because Mark submitted it doesn't mean it didn't get preprocessed by the almighty Alex! Or maybe Mark is his sockpuppet. Or maybe they're just as brillant as each other.

    PS. 'brillant' is not a typo; you must be new here!

    You've been misled into thinking that was the referenced typo.

  • Rob Z (unregistered)

    Works fine in Oracle pl/sql:

    DECLARE a BOOLEAN; BEGIN IF ( a ) THEN DBMS_OUTPUT.PUT_LINE( 'true' ); ELSIF ( not a ) THEN DBMS_OUTPUT.PUT_LINE( 'false' ); ELSE DBMS_OUTPUT.PUT_LINE( 'null=> other universe?' ); END IF; END;

    Output: 'null=> other universe?'

  • TheRider (unregistered) in reply to Ben Jammin
    Ben Jammin:
    Mike:
    shouldn't it be ... else if !patient.sick? || patient.dead? ...
    Plus, if you're not sick, hopefully being buried isn't the solution. Obviously, patient.sick? needs to be a tri-state boolean of true, false, and LIFE_NOT_FOUND.
    Don't you make me spit my coffee on the screen. Too much work cleaning it...
  • u (unregistered)

    Is doing nothing when a== 0, b >= 30 and c != null intentional? If not it somehow proves the point...

  • (cs)

    the correct construct is of course to first create a boolean of the condition.

    bool val = (a > 10 || b < 30 || c = null );
    if( val == true )
    {
      do_soemthing();
    }
    else if ( val == false )
    {
      do_something_else();
    }
    else if ( val == fileNotFound )
    {
       do_anything_you_like();
    }
    
  • foo (unregistered)

    Reminds me of another "experienced" developer, who'd always use the mouse to select items and then do copy&paste through the context menu. Another one of those valued developers with over a decade of experience ...

  • Nemo (unregistered) in reply to Ben Jammin
    Ben Jammin:
    Mike:
    shouldn't it be ... else if !patient.sick? || patient.dead? ...
    Plus, if you're not sick, hopefully being buried isn't the solution. Obviously, patient.sick? needs to be a tri-state boolean of true, false, and LIFE_JIM_BUT_NOT_AS_WE_KNOW_IT.

    FTFY

  • foo (unregistered)
    Doug adamantly refused to make the changes that Matt asked, and Matt refused to sign off to allow his development to advance.
    That was when Doug threatened Matt: "Now do sign off my changes OR ELSE ... do not sign off my changes!"
  • allo (unregistered)

    if(i++ == 1){ doSomething(); }else if(i++ == 1){ doSomethingElse(); }

  • Anoldhacker (unregistered)

    It's probably late for this, but...

    The real problem with

    if (condition) {...} elsif (reverse_of_condition) {...} end

    Is not that YOU might mess up your reverse_of_condition computation. We can assume that YOU are smart enough to use !(condition) for that. The real problem is that at some point condition will need to be modified. By someone who has never seen this code before. Who isn't as smart as you.

    That's what "doubled the complexity" meant.

  • (cs) in reply to Michael P
    Michael P:
    Some coding standards (like, say, the ones used for C++ on the US Joint Strike Fighter program) specifically require an if/else if chain to be terminated with either an "else" handler or a comment that explains why there is no else. That seems like good practice for any software with significant safety implications.
    Just in case of FILE_NOT_FOUND in your boolean.
  • chris (unregistered) in reply to Rob Z
    Rob Z:
    Works fine in Oracle pl/sql:

    DECLARE a BOOLEAN; BEGIN IF ( a ) THEN DBMS_OUTPUT.PUT_LINE( 'true' ); ELSIF ( not a ) THEN DBMS_OUTPUT.PUT_LINE( 'false' ); ELSE DBMS_OUTPUT.PUT_LINE( 'null=> other universe?' ); END IF; END;

    Output: 'null=> other universe?'

    IIRC it's the ANSI standard: null != null. Its the same in T-SQL (SQL Server) by default. One hell of an annoying convention.

  • TRWTFVB (unregistered)

    TRWTF is that he had decades of experience in VB

  • iusto (unregistered) in reply to foo
    foo:
    Reminds me of another "experienced" developer, who'd always use the mouse to select items and then do copy&paste through the context menu. Another one of those valued developers with over a decade of experience ...

    Now you're exaggerating a little. If you had said, a guy scrolls up 2 pages of text to copy a short word so that he can paste it where he was below (to avoid typing it), then I'd understand. I noticed a couple of devs doing that for as little as 4-characters. Not to mention that IDE at the time was Visual Studio, where intellisense is present.

  • DB (unregistered) in reply to Ben Jammin
    Ben Jammin:
    Mike:
    shouldn't it be ... else if !patient.sick? || patient.dead? ...
    Plus, if you're not sick, hopefully being buried isn't the solution. Obviously, patient.sick? needs to be a tri-state boolean of true, false, and LIFE_NOT_FOUND.

    HAHAHAAHAHHAA

  • Paul Neumann (unregistered) in reply to iusto
    iusto:
    foo:
    Reminds me of another "experienced" developer, who'd always use the mouse to select items and then do copy&paste through the context menu. Another one of those valued developers with over a decade of experience ...
    Now you're exaggerating a little. If you had said, a guy scrolls up 2 pages of text to copy a short word so that he can paste it where he was below (to avoid typing it), then I'd understand. I noticed a couple of devs doing that for as little as 4-characters. Not to mention that IDE at the time was Visual Studio, where intellisense is present.
    Real developers have no mouse. Real developers have no keyboard. Real developers whistle at 900 baud to a modem attached to ttyS0!

Leave a comment on “But...Anything Can Happen!”

Log In or post as a guest

Replying to comment #:

« Return to Article