• (disco) in reply to dkf
    dkf:
    You've changed the semantics there, because you're now evaluating `this.SendMail(…)` irrespectively of whether the preceding two boolean conditions have been satisfied. Fortunately, compilers don't make this sort of mistake.

    True. However:

    1. Contrived example
    2. Not all languages short-circuit when evaluating Boolean operators; some of them you can even configure on the fly.

    I'll still contend (in general) if you have an if statement that looks like a George R R Martin description of a banquet scene; it's can be easier to understand at a glance if it looked something like:

    if (goodFood & banquetTables & heavilyArmedSoldiers & crossBowMenOnBalcony & BoltonsPresent)
    {
        // Red Wedding
    }
    
  • (disco) in reply to CodeSlave
    CodeSlave:
    2) Not all languages short-circuiting when evaluating; some of them you can configure then on the fly.

    Hey guys... TRWTF? I think I found it.

  • (disco) in reply to PJH

    https://www.youtube.com/watch?v=YuJEeAVWG4o This is the band that should have represented us at Eurovision. Sebastian schmebastian.

  • (disco) in reply to gnasher729

    Comments are good (and should not be any more likely to be wrong than a descriptive variable name).

    And if you happen to need to set a breakpoint on if(... complicated expression ...), you can evaluate ... complicated expression ... easily enough with a simple copy-and-paste.

  • (disco) in reply to sloosecannon
    sloosecannon:
    CodeSlave:
    2) Not all languages short-circuit when evaluating Boolean operators; some of them you can even configure on the fly.

    Hey guys... TRWTF? I think I found it.

    Happier? (please excuse any baby-induced-sleep-deprivation that may have impaired my English this morning; it was a rough night)

  • (disco) in reply to CodeSlave
    CodeSlave:
    sloosecannon:
    CodeSlave:
    2) Not all languages short-circuit when evaluating Boolean operators; some of them you can even configure on the fly.

    Hey guys... TRWTF? I think I found it.

    Happier? (please excuse any baby-induced-sleep-deprivation that may have impaired my English this morning; it was a rough night)

    For once I actually *wasn't* being a pe[n]dantic spellar/gramming dickweed, but yes, that is better :)
  • (disco) in reply to RaceProUK

    not unlike is quite common in English

    Oh yeah, I know... it's fine as a speech idiom, it was just very evil when slipped into a sentence to demonstrate how bad double negative boolean operations in code are.

  • (disco) in reply to RaceProUK
    RaceProUK:
    levesque:
    "not unlike"... that's just evil.
    `not unlike` is quite not uncommon in English

    <blah blah blah iknowitsnotreallyfunny

  • (disco) in reply to Steve_The_Cynic
    Steve_The_Cynic:
    every single one of the checks would be clearer if written as an explicit test directly in the relevant if().

    :+1:

  • (disco)

    My hypothesis, which I haven't seen anyone else mention, is that the programmer was told at some point that an if(...) can only contain a boolean, unlike languages like C, where you can use an integer, or PHP, Python, etc., where you can use pretty much any variable type. The programmer, not knowing any better, thought that this meant that it can only have a single boolean variable.

    That sounds like a pretty typical :wtf:-generating programmer.

  • (disco)

    After reading the whole post, there is a big question mark left:

    Is "cow-orker" a mistake or an intended typo?

  • (disco) in reply to Antarctica

    Great, now that the elephant in the room has been pointed out....

  • (disco) in reply to Antarctica

    Intended :wink:

  • (disco)

    I thought they were gonna use a bitfield in a boolean field. like:

    bool count = 0;
    if (recipients.Items.Count !=0) count |= 1 << 0;
    if (!string.isNullOrEmpty(mailInfo.From)) count |= 1 << 1;
    /* ... */
    return count == 42; // count == 0b101010
    
  • (disco) in reply to Antarctica
    Antarctica:
    cow-orker

    http://www.catb.org/jargon/html/C/cow-orker.html

  • (disco)

    I didn't make it past the first error message:

    throw new ArgumentNullException("
                 recepients", 
                 "Recipient collection is empty, there is no recipients to send to.");
    

    All your base are belong to us.

  • (disco) in reply to RaceProUK
    RaceProUK:
    It does when it performs optimisations that are impossible in the source language

    Such as? (not snark: I'm genuinely curious.)

  • (disco) in reply to NBeezy

    Bitfields and decimal representation? Naughty programmer spank spank spank.

  • (disco) in reply to kupfernigk
    kupfernigk:
    RaceProUK:
    It does when it performs optimisations that are impossible in the source language
    Such as? (not snark: I'm genuinely curious.)
    I can't think of any off the top of my head. But then I don't write compilers for a living.
  • (disco) in reply to RaceProUK

    Surprised nobody's picked up on this appalling instance of inverse logic:

            count = !this.SendMail(mailMessage, testMode);
            if (!count) {
               sendMailLog.SuccessMessages.Add(current.EmailAddress);
               current.Status = JobWorkStatus.Complete;
               count = current.JobId <= 0;
    
               if (!count) {
                  current.Save();
               }
            }
    

    Er, so count is not having sent the message, and if not count then add address to list of success message. And then it gets worse.

  • (disco) in reply to gnasher729
    gnasher729:
    So for example, if you set and use the boolean, then call a function, the compiler needs to find out that the variable is set again before any future use, so it can avoid saving the variable from a register to the stack and restore it. With six variables, each one is not even used after the first use, which makes that analysis a lot easier.
    I don't buy this. The compiler still needs to figure out the "each one is not even used after the first use" fact, and the step from there to finding live ranges for the same variable is small. And compilers *have* live range analysis, so you don't need to much worry about how difficult it is to do, because at this point "easier than easy" isn't much different from "easy."
  • (disco) in reply to RaceProUK

    According to British naming conventions the variable should have be named earl.

  • (disco) in reply to sirhegel
    sirhegel:
    According to British naming conventions the variable should have be named earl

    No, "Earl" is a US first name. Earl ("Eorl") is actually Anglo-Saxon and predates the Norman aristocracy that set up our present system. But in any case British people aren't given names like Earl, Prince and so on because these are titles, i.e. reserved words. It would be like naming someone "Mister" or "Sir". In the US they are not titles and so can be used as personal names (i.e. variable names.)

  • (disco) in reply to kupfernigk

    You deserve the pedantic badge for that. Great explanation, though :)

  • (disco) in reply to NTAuthority

    I'm really surprised that on one commented on the author's, apparent, complete lack of understanding of how to properly use a "while" statement:

    while(true) {
        if(true)
            break;
    }
    

    Really? There are potential reasons why you would want to manually loop though an enumeration, but I can't think of a single reason why you would intentionally setup this potential infinite loop (not in this context). Just wait for the day that something goes wrong, and that condition never lets the "break" happen. That'll be a not fun day for somebody.

  • (disco) in reply to obeselymorbid
    obeselymorbid:
    Depends on your version of C.I guess you haven't worked with typedef unsigned char bool.

    I have. But we are in the second decade now, and anything before C11 is not C anymore. Oh wait, <stdbool.h> was part of C99 already. Are you using compilers that live more than 16 years in the past?

  • (disco) in reply to gnasher729

    MSVC versions before 2013 didn't support C99 at all. MSVC 2013 only has partial support, but that does include _Bool and bool (which expands to _Bool).

  • (disco) in reply to Jerome_Viveiros

    Just having the tests inline makes it a hell of a lot more readable anyway. If I'm around that point in the code, I want to know what is happening and I don't want it hidden behind layers (and sometimes layers) of other files.

  • (disco) in reply to RaceProUK
    RaceProUK:
    The biggest : a Boolean called count

    Maybe. If this were Java I'd say the biggest :wtf: is the lack of the final keyword in the declaration of the mis-named count variable, which would have stopped this code from compiling at all. But I don't know enough about .Net to know if readonly can be used the same way as final for local variables.

  • (disco) in reply to another_sam

    I think it does; never tried it though

  • (disco) in reply to Severity_One
    Severity_One:
    boolean count1, count2, count3, count4, count5, count12;

    You see? It still could have been worse.

    boolean count1, count2, count3, count4, count5, ah_ah_ah;


    Filed under: Stealing the joke in the article
  • (disco) in reply to RaceProUK
    RaceProUK:
    I think it does

    Good to know but I'll have forgotten by the next time it will be useful to me. :smile:

    RaceProUK:
    never tried it though

    You're bad people. Immutability is awesome and eliminates or reduces entire classes of bugs. I have Eclipse set to add the final keyword when I save to all variables that aren't written again, which makes the variables written multiple times stand out for me to fix.

  • (disco) in reply to another_sam

    To be fair, it's very rare I have a variable I could make readonly

  • (disco) in reply to RaceProUK
    RaceProUK:
    To be fair, it's very rare I have a variable I could make readonly

    How does that happen? In my experience the vast majority of variables are written only once. Does your code need more decomposition or something maybe?

  • (disco) in reply to another_sam

    The stuff I work on often requires a fair amount of calculation. And I do tend to inline a fair amount too. Nothing too silly, otherwise it'd be an unmaintainable mess :smile:

  • (disco) in reply to RaceProUK
    RaceProUK:
    The stuff I work on often requires a fair amount of calculation.
    final int partOneCalculation = calculatePartOne(); final int partTwoCalculation = calculatePartTwo(); fina int finalCalculation = calculateFinal(partOneCalculation, partTwoCalculation);
  • (disco) in reply to another_sam

    I see the merit in the approach; whether I use it or not though… no idea. I'll keep it in mind though.

  • (disco) in reply to another_sam

    To bastardize a quote for my own purposes: "I am not able rightly to apprehend the kind of confusion of ideas that could provoke such code."

    another_sam:
    boolean count1, count2, count3, count4, count5, ah_ah_ah;
    Filed under: Stealing the joke in the article

    boolean count1, count2, count3, count4, count5, ah_ah_ah, FILE_NOT_FOUND; Am I doing it right?

  • (disco) in reply to Severity_One

    I was waiting for this. First reference to 'filenotfound'!!

  • (disco) in reply to another_sam

    How would the lack of final stop that code from compiling?

  • (disco) in reply to Buddy
    Buddy:
    How would the lack of final stop that code from compiling?

    Lack of final doesn't stop it compiling, liberal use of final stops it compiling. Liberal use of final makes count without final obvious, drawing attention, hopefully the right kind, and an opportunity for improvement.

  • (disco) in reply to another_sam

    Pah. Tricked me with your upside-down Aussie logic. Do your for loops go around the other way too?

  • (disco) in reply to tenshino
    tenshino:
    You deserve the pedantic badge for that. Great explanation, though

    I rejoice in my pendantry. When you get to my age, that and telling people to remove themselves from my lawn is about all you have left.

  • (disco) in reply to RaceProUK
    RaceProUK:
    I see the merit in the approach; whether I use it or not though… no idea. I'll keep it in mind though.

    Basically what Erlang does - immutables.

  • (disco) in reply to gnasher729
    gnasher729:
    But we are in the second decade now, and anything before C11 is not C anymore.

    :wtf:

    gnasher729:
    Oh wait, was part of C99 already. Are you using compilers that live more than 16 years in the past?

    Yes, I'm using C compilers with partial C99 implementation without bool which are not likely to change even in the next 16 years.

  • (disco) in reply to RaceProUK
    RaceProUK:
    To be fair, it's very rare I have a variable I could make readonly
    I'm constantly making variables readonly.
  • (disco) in reply to urkerab
    urkerab:
    I'm ```const```antly making variables ```readonly```.
    I see that.
  • (disco) in reply to gnasher729

    For a true bool type b=1000 should give an error and not revert to one.

    And in python: True + 5 => 6

  • (disco) in reply to Dlareg
    Dlareg:
    And in python:True + 5 => 6
    [image]
  • (disco) in reply to antiquarian

    I totally agree... they should have fixed that in python 3000. It is really terrible.

Leave a comment on “The Busy Little Boolean”

Log In or post as a guest

Replying to comment #:

« Return to Article