• No'am (unregistered)

    frist = !frist

    or maybe, frist!

  • Nick (unregistered) in reply to No'am

    if (!fristJokeStillFunny) then fristJokeStillFunny = true; if (fristJokeStillFunny) then fristJokeStillFunny = false;

  • noone (unregistered)

    what do we learn from this? no matter how long you do something it does not mean that you are good at it.

  • (cs)

    If (firstpost == frist) deleteFirstPost();

    If (secondpost == frist) callSecondPosterIdiot();

    //See what I did there?

  • 50% Opacity (unregistered)

    Booleans are hard, man. The previous statement is maybe !not entirely completely unfalse.

  • Kata (unregistered)

    =! != != !

  • (cs)

    And why didn't Ben suggest that they try this out? Making a wager would have been a good idea, too.

  • ROFL (unregistered) in reply to Kata
    Kata:
    =! != != !
    THIS!

    PS - Nomination for featured comment (I presume Alex scrapes for the word featured comment - can't think of many other reasons to stay with this software)

    nulla - There's another reason..

  • mugo (unregistered)

    makes no sense to talk to such guys, just check from time to time what they checkin and then have some funny stuff to read and share

  • (cs)
    value ^= 1;
    

    Or, if your language does not convert non-zero integers to true:

    value ^= true;
    

    Or, if the other people on your team are morons:

    value = !value;
    

    If you want to be explicit:

    value = value ? false : true;
    

    If you want to be explicit and others are not smart enough to understand the ternary conditional operator (or your language does not have/messed up the TCO):

    if(value)
        value = false;
    else
        value = true;
    

    If you are paid by the character/SLOC:

    if ( value == true )
    {
        Logger.getLogger(this.getClass().getCanonicalName()).debug("Before: value == "+value);
        value = false;
        Logger.getLogger(this.getClass().getCanonicalName()).debug("After: value == "+value);
    }
    else if ( value == false )
    {
        Logger.getLogger(this.getClass().getCanonicalName()).debug("Before: value == "+value);
        value = true;
        Logger.getLogger(this.getClass().getCanonicalName()).debug("After: value == "+value);
    }
    else
    {
        Logger.getLogger(this.getClass().getCanonicalName()).debug("Value changed? Possible synchronization error!");
        throw new IllegalStateException("Value changed while comparing!");
    }
    

    Don't forget documentation and unit tests, though.

  • Kev (unregistered)

    I've seen some pretty poor new developers, but I can't believe anyone could stay working for a company and not understand how an If statement works, let alone get to be a senior developer. Surely this can't be genuine

  • qbolec (unregistered)

    As he is refered to as "senior", perhaps, he has just forgotten.

  • Bill Coleman (unregistered)

    You can't fix stupid....

  • Kasper (unregistered) in reply to Kata
    Kata:
    =! != != !
    That is so true.

    Reminds me of a mistake I had to debug once. There was a configuration file, which contained some clauses of the form <attributename>=<regex> or <attributename>!=<regex>. Since ! was not a valid character in the attributename, this syntax was unambiguous. But accidentally someone had messed up in one configuration file and written <attributename>=!<regex>. Turns out this would also be parsed as valid, since ! is a valid character in a regex.

  • Kasper (unregistered) in reply to SeySayux
    SeySayux:
    messed up the TCO
    Any example of a language, which did mess it up?
  • G (unregistered) in reply to qbolec
    qbolec:
    As he is refered to as "senior", perhaps, he has just forgotten.
    Hehe. More like a senile developer.
  • TRick (unregistered)

    This is one of those times where drawing a flowchart really helps.

  • Pista (unregistered)

    Some time ago we had here an article about a guy who had problem understanding the try-catch-finally construct, now we've got this one having problem with the if-else. What next? A moron who can't write an assignment? Oops, I'm sorry: here we've got that too, so this is a double WTF!

  • LimEJET (unregistered) in reply to Kasper

    PHP springs to mind, with this nugget:

    Unlike (literally!) every other language with a similar operator, ?: is left associative. So this:
    $arg = 'T'; $vehicle = ( ( $arg == 'B' ) ? 'bus' : ( $arg == 'A' ) ? 'airplane' : ( $arg == 'T' ) ? 'train' : ( $arg == 'C' ) ? 'car' : ( $arg == 'H' ) ? 'horse' : 'feet' ); echo $vehicle;

    prints horse.

    (Taken from http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/)
  • Mike D. (unregistered)

    Jim,

    When you get a moment, could you look at a couple unit tests I've written? They don't seem to be giving me the expected results.

    Source:

    #include <iostream>

    using namespace std;

    bool test_one(bool showOptionsButton) { if (showOptionsButton == true) showOptionsButton = false; if (showOptionsButton == false) showOptionsButton = true; return showOptionsButton; }

    bool test_two(bool showOptionsButton) { showOptionsButton = !showOptionsButton; return showOptionsButton; }

    int main() { cout << "test_one(false) returns " << test_one(false) << endl; cout << "test_one(true) returns " << test_one(true) << endl; cout << "test_two(false) returns " << test_two(false) << endl; cout << "test_two(true) returns " << test_two(true) << endl; return 0; }

    Output:

    test_one(false) returns 1 test_one(true) returns 1 test_two(false) returns 1 test_two(true) returns 0

    http://ideone.com/du77Rl

    -- Ben

  • (cs)

    You don't need to explain anything.

    Just each write out truth tables, then compare them. If Jim is still unable to get it, write out step-by-step truth tables.

    If he's still unable to get it, either resign, or get Jim fired.

  • Tim (unregistered) in reply to Kata

    when doing parameter validation in C I often needed to check whether one or the other or both string parameters was not null. this led to lots of expressions like

    if (!!a != !!b) { ReturnError("you must either specify both a and b or omit them both); }

  • (cs) in reply to Kasper
    Kasper:
    SeySayux:
    messed up the TCO
    Any example of a language, which did mess it up?

    In Python, it's a little messed up:

    value = False if value else True
  • d (unregistered)

    Bool OldValue = Value; while(Value == OldValue) { switch(rand() % 3) { case 0: Value = True; case 1: Value = False; case 2: Value = FileNotFound; }

  • (cs) in reply to Kasper
    Kasper:
    SeySayux:
    messed up the TCO
    Any example of a language, which did mess it up?
    Visual Basic .Net has it implemented as a function. A non-generic function, that takes one Boolean and two Object as arguments and returns Object (plus, the fact that both sides are evaluated in both cases, but that one is inevitable when using functions).
  • LK (unregistered)

    So this could be replaced by

    if (showOptionsButton == false) showOptionsButton = true;

    It cannot be replaced by simply

    showOptionsButton = true;

    because that would change the result when showOptionsButton == FILE_NOT_FOUND;

  • (cs)

    "Some people have 10 years of experience. Others have 1 year of experience 10 times."

    (source unknown)

  • (cs)

    I'll be honest, I've done this once because I had other things on my mind. But not with an if statement quite so trivial. Still, at a glance you can make such a mistake.

  • Rob (unregistered)

    The Schrödinger's cat indicator. If you look at the value of a boolean, the state changes.

  • Dan (unregistered) in reply to Kata
    Kata:
    =! != != !

    TRUE factorial?

  • tobor the mediocre (unregistered)

    Jim must be one of those "1 year of experience 12 times" type senior developers.

  • Foo (unregistered) in reply to Tim
    Tim:
    when doing parameter validation in C I often needed to check whether one or the other or both string parameters was not null. this led to lots of expressions like

    if (!!a != !!b) { ReturnError("you must either specify both a and b or omit them both); }

    wow, just wow.

    You sir, are a true master of building a codebase only you can work ok.

    Personally, I might want to let someone else do maintainance on stuff I wrote, so I'd let them have a clue what it does.

    if ((a==null) != (b==null)) {}

    yes, could have used an xor, but that's not as readable.

  • Your Name (unregistered) in reply to xorsyst
    xorsyst:
    Kasper:
    SeySayux:
    messed up the TCO
    Any example of a language, which did mess it up?

    In Python, it's a little messed up:

    value = False if value else True
    The syntax is weird, sure, but it still works the same as normal languages.
  • Xeno (unregistered) in reply to Medinoc

    It was added as an operator in 2008.

    Dim s as StringBuilder
    Dim d as String = "d"
    Dim t as String = If(True,d,s.ToString)
    

    s.ToString will never be evaluated. Replacing the line with

    IIf(True,d.ToString,s.ToString).ToString
    will throw a Null Reference exception.

  • (cs)

    Totally believe this, I've seen such work from a "senior" software engineer before. It wasn't malice, just caring about getting something done fast and not paying attention to it, because as long as you tell the boss it's done who cares if you have to fix it later? The feature was implemented.. nobody said it had to be implemented CORRECTLY.

  • Rando (unregistered) in reply to Kata

    Is this some secret code for frist?

  • chris (unregistered) in reply to Medinoc
    Medinoc:
    Kasper:
    SeySayux:
    messed up the TCO
    Any example of a language, which did mess it up?
    Visual Basic .Net has it implemented as a function. A non-generic function, that takes one Boolean and two Object as arguments and returns Object (plus, the fact that both sides are evaluated in both cases, but that one is inevitable when using functions).
    And people get into VB on the grounds that it's easier than Java or C#??
  • ¯\(°_o)/¯ I DUNNO LOL (unregistered)

    Clearly Jim was considering the case where showOptionsButton == FileNotFound.

  • QJo (unregistered) in reply to Kev
    Kev:
    I've seen some pretty poor new developers, but I can't believe anyone could stay working for a company and not understand how an If statement works, let alone get to be a senior developer. Surely this can't be genuine

    You'd be surprised. Some time ago when I joined a company as a FORTRAN developer (yes, a long time ago) I was assigned a mentor who, soon after I had settled in my seat, asked me how to write a DO loop. Not that she was testing me to check that I had the appropriate knowledge, but because she genuinely didn't know how do it. She'd had a piece of code bounced back 3 times from her boss and still hadn't managed to do what it needed to do.

    In the words of King Crimson: "Please teach me." Mmm. I taught her.

    I later asked around to find out how she had got to be a mentor. "By begging," I was informed.

  • Dschoordsch (unregistered) in reply to Kata

    The ! belongs to the side which isn't equal.

  • (cs)
    “If I use an else, it’ll run both clauses. I only want it to run one.”

    I don't know in what way I would have reacted to this. Violence seems adecuate.

  • (cs) in reply to xorsyst
    xorsyst:
    Kasper:
    SeySayux:
    messed up the TCO
    Any example of a language, which did mess it up?

    In Python, it's a little messed up:

    value = False if value else True

    I love this quote from the PEP which defines the conditional expression:

    Previous community efforts to add a conditional expression were stymied by a lack of consensus on the best syntax. That issue was resolved by simply deferring to a BDFL best judgment call.

    Basically, BDFL said: "fuck it, let's implement it like this".

    It's also funny that if you google for BDFL, a picture of van Rossum is shown.

  • yoda (unregistered)

    !first

  • NeXT-Generation (unregistered)

    "No, it won't" Yes it will you idiot. What kinda stupid man makes you the mentor? And to make it even worse, you didn't do the BEST option in the first place! Nothings easier than x = !x;

  • Jeff Dege (unregistered)

    My second day, on my very first programming job, working in C with an ISAM database library, I was reading through the code, and went to the lead, who was supposed to be breaking me in, with a question.

    Q: Why are we always searching through the database records sequentially? Surely the database library provides some sort of mechanism for searching for a record using an index.

    A: I don't think it does.

    Of course, it didn't take me long to find the feature in the ISAM library's documentation.

    Two months later, he got a bonus for the significant speed improvements he'd made in the application.

  • Adrian Ratnapala (unregistered) in reply to Kata

    My thoughts exactly!!

  • Bill (unregistered) in reply to Kata

    That that that that boy wrote is not that that that that boy wrote.

  • Luiz Felipe (unregistered) in reply to Medinoc
    Medinoc:
    Kasper:
    SeySayux:
    messed up the TCO
    Any example of a language, which did mess it up?
    Visual Basic .Net has it implemented as a function. A non-generic function, that takes one Boolean and two Object as arguments and returns Object (plus, the fact that both sides are evaluated in both cases, but that one is inevitable when using functions).
    No, Visual Basic implemented it as a ternary operator, it happens to use function sintax, but the compiler optimize it away using type inference.
  • trololo (unregistered)

    "... I’d love to explain the basics to you, but I really need to get this feature finished."

    And so I finished the new feature :

    Switch(showOptionsButton){ case (true): showOptionsButton = false; case (false): showOptionsButton = true; default: showOptionsButton = if(rand()%2); }

  • taytay (unregistered)

    real wtf is people not noticing it is simply

    showOptionsButton = true;

Leave a comment on “The Truth of the Matter”

Log In or post as a guest

Replying to comment #:

« Return to Article