• Industrial Automation Engineer (unregistered)

    Probably copy-pasted from a website known to provide many snippets of code that just 'work.' (for any given value of 'work.')

  • Prime Mover (unregistered)

    I've been trying to think of a pun that hasn't been used, but my brain's a bit num today.

  • Just Some Guy (unregistered)

    What I love about that enum is that it assigns True to 0 and False to 1.

  • akozakie (unregistered) in reply to Industrial Automation Engineer

    Yeah, but that's supposed to be the one starting with st and ending with low, not the one starting with th and ending with wtf...

  • (nodebb) in reply to Just Some Guy

    Again.

    What is it with those guys?

  • löchleindeluxe (unregistered) in reply to Just Some Guy

    Well, that's shell semantics, isn't it? retval 0 means ok, so that's the "good" value, like "true". (And if you think about retvals and && etc. too hard, you'll confuse yourself senseless.)

  • Mike5 (unregistered)

    I blame this site. It's been advertising the FileNotFound boolean for so long someone was bound to use it. :p

  • I dunno LOL ¯\(°_o)/¯ (unregistered)

    Assuming NUM is really the "number of items in the enum" idiom, then trying to imagine, before my morning caffeine, why someone would want to iterate over the range of TRUE, FALSE, and FILE_NOT_FOUND is causing my brain to segfault.

  • (nodebb) in reply to löchleindeluxe

    Well, that's shell semantics, isn't it?

    It is, but there's a very strong "so the fucking fuck what" aspect there. We aren't programming in shell here, so we should follow the semantics of the language we are programming in.

  • wut (unregistered)

    So, uh, we're not even going to talk about the part where the ordinal values TRUE == 0 and FALSE == 1, inversing every standard practice around booleans?

  • True = 0 (unregistered)

    Uh, TRUE=0 is probably an extension of the C/C++ practice of making SUCCESS=0 and any value other than 0 indicating an error condition. After all, there's only one SUCCESS, but there can be many kinds of FAILURE. I'm not saying that making TRUE=0 is good practice. But there might be an excuse.

  • ooOOooGa (unregistered) in reply to I dunno LOL ¯\(°_o)/¯

    To reinvent a switch statement of course.

    iterate over the values, then have an if-else-if stack to do different things depending on which values is passed in.

  • (nodebb) in reply to I dunno LOL ¯\(°_o)/¯

    For statistics? Allocate NUM integers, fill them as a histogram, output it somewhere nobody will bother to read it...

  • Carl Witthoft (google)

    I know! I know! They have their own classes, using Hungarian notation. So "ENUM" means "Editable Number" but if things don't work out, downgrade it to class NUM, a non-editable number.

  • tbo (unregistered)

    You can't convince me this isn't the same code as the original.

  • Harry (unregistered)

    Since TRUE means that the setting in the config file was true, and FALSE means that the setting in the config file was set to false, and obviously FILE_NOT_FOUND means that the config file was missing, I would guess that NUM indicates that the value from the config file was a number.

    ENABLE_FROBBING=TRUE ENABLE_CHEAT_MODE=FALSE NUMBER_OF_DUCKS=7

  • mushroom farm (unregistered)

    I have become Comfortably NUM

  • Brad (unregistered)

    I will not subscribe to your false dichotomies!!!

  • Loren Pechtel (unregistered)

    What's so horrible about an extra enum there? While it doesn't make sense on a boolean, if you have more states having a Count at the end of your enum can simplify life at times. I've got one in mind where there are multiple arrays where the enum is the index. In an ideal world that wouldn't happen, but we live in the real world.

  • Officer Johnny Holzkopf (unregistered) in reply to Harry

    In how far is "settings in a config file" (as provided in your example) a thing one would call a "bool", except maybe it's an acronym for "Build On top Of Logic". It would be understandable if, following the configuration file evaluation approach, config settings can be either "TRUE" (value 0) or "FALSE" (value 1), the config file itself cannot be found - FILE_NOT_FOUND, or some config setting has been assigned a number - NUM. Mapping those... things as arbitrary values to settings (so the value is "TRUE" or "FALSE", but could be "YES" or "NO", "ON" or "OFF", "WANT" or "DONOTWANT", or "1" or "0") and then to program-internal things sounds absolutely possible. Even then, FILE_NOT_FOUND would not be in the same row as TRUE, FALSE, and NUM. But to summarizse, nothing of that is actually boolean and therefore should probably not be expressed as an enum Bool.

  • Harry (unregistered) in reply to Officer Johnny Holzkopf

    Presumably they couldn't be bothered to change the name. Or it never occurred to anyone that it was even possible to do so.

  • (nodebb) in reply to Loren Pechtel

    That would probably why NUM is used. Somewhere else there's another enum handled the same way, with a final sentinel value of COUNT. Another that uses LAST for the purpose, and another that ends with END....

  • kaewberg (unregistered)

    I have definitely used MAX_FOO in an enum...

  • (nodebb) in reply to True = 0

    After all, there's only one SUCCESS, but there can be many kinds of FAILURE.

    S_FALSE would like to talk to you about this "only one SUCCESS" thing.

    Um. S_FALSE is defined to be 1, by the way, while S_OK, also a success, is zero.

  • RLB (unregistered) in reply to True = 0

    Uh, TRUE=0 is probably an extension of the C/C++ practice of making SUCCESS=0 and any value other than 0 indicating an error condition.

    Except that in C, true is non-zero, and false is zero. That is, using this enum, if (TRUE) would not trigger, and if (FALSE) would.

    The only place where 0 is success and not-0 is failure is, as mentioned above, in the return value to main() - in other words, to the shell.

    (No, strcmp() does not count. 0 does not mean success, it means equal; negative means smaller than the other and positive means larger. Any of those could be a success, depending on what you're comparing.)

  • Anonymous (unregistered)

    I've actually seen this technique before! And it does make sense, sometimes. I've actually used this in callback-related code where I needed to iterate over all the callback lists for all event types. It can also be useful if you're consuming data from an outside source (i.e. it's not validated by the compiler) and you want to make sure it's a valid enum value.

    Whether this makes sense in a bool value...eeeeeeh? Maybe it's just something the style guide said to put on every enum.

  • John (unregistered)

    Why stop at file_not_found

    { true, false, file_not_found, file_is_empty, too_many_rows, missing_primary_key, memory_overflow, integer_too_big, impossible_date, .., }

  • Arjun Singh (unregistered)
    Comment held for moderation.
  • Rahul Kumar (unregistered)
    Comment held for moderation.

Leave a comment on “Numb to Truth”

Log In or post as a guest

Replying to comment #:

« Return to Article