• nelle (unregistered)

    #define FILE_NOT_FOUND 3 // is missing

    captcha: tesla - yeah charge me up ... ups ...

  • Jens (unregistered)

    MAYBE I just read that...

    I often sit back with the feeling, that something is missing. There's gotta be some kind (good or most likely bad) of explanation to WHY this was done.

    CAPTCHA: Sanitarium - Thanks, needed that after reading this

  • skztr (unregistered)

    It's forwards-compatible with quantum computers. No WTF here.

  • MB (unregistered)

    Another variation on a classic anti-pattern.

    Hooray!

  • anon (unregistered)

    What? No FileNotFound?

    captcha: doom - it shall be coming to Sarnath

  • Ed Heil (unregistered)

    Dude should be programming Haskell!

    http://www.haskell.org/onlinelibrary/maybe.html

  • Winter (unregistered)

    Did anyone mention FILE_NOT_FOUND yet because I think about 30 more people should post that. Also can we define BRILLANT as well for completeness

  • passer by (unregistered) in reply to Ed Heil

    #define MAYBE_NOT 3

  • codemoose (unregistered) in reply to passer by

    #define LIKELY 4

  • MadMike (unregistered)

    Maybe some sort of lazy-evalutation scheme?

  • TheMagic8Ball (unregistered)

    #define ALL_SIGNS_POINT_TO_YES 13

  • steven22 (unregistered)

    If he had called it UNKNOWN instead of MAYBE, would you guys be okay with it?

  • erKURITA (unregistered)

    #define WTF (!TRUE && !FALSE && FILENOTFOUND)

    B)

  • (cs) in reply to Winter
    Winter:
    Did anyone mention FILE_NOT_FOUND yet because I think about 30 more people should post that. Also can we define BRILLANT as well for completeness

    Don't give them ideas. This board doesn't understand the concept of shelflife when applied to injokes.

  • Super the Pieman. (unregistered)

    Shenanigans.

    And tat.

  • (cs)

    I like the fact that someone else could define FALSE as 1 or 50 and his code won't even fix that.

  • J Random Stranger (unregistered)

    This sounds like a workaround for the sorts of glitches that always come up when you test for geometric intersection when using floating point forms.

    There are shapes that clearly intersect or not intersect. There is also a class of shapes where roundoff errors can give you false answers. Generally this class involves abutting shapes where the end vertices are not coincident. Because the two shapes touch, but don't intersect, roundoff errors can give you a relatively random result.

    Answering "MAYBE" may be a bit silly, but having some way of indicating that there has been a precision loss is a good idea in these sorts of applications.

  • (cs) in reply to TheMagic8Ball
    TheMagic8Ball:
    #define ALL_SIGNS_POINT_TO_YES 13

    Compiler produced this warning:

    REPLY_HAZY_TRY_AGAIN

  • Unomi (unregistered)

    Indeed it is somewhat philosophic or forward-compatible with quantum informatica like someone else mentioned.

    While it can not be defined as TRUE, it is simply FALSE. Who doesn't try to shoot, will always miss. So negative is default here. You can't say, 'Who doesn't try to shoot, will maybe miss'. Simple not true (thus false).

    MAYBE is like 'IT_DEPENDS' or coming to some inner_check_function_wisdom to be called and resulting in either TRUE, FALSE or BOTH. Japanese people could refer to a status called 'MU'..... Not typical programming (thus an anti-pattern).

    CAPTCHA: ewww (indeed, to ugly to even spit on)

    • Unomi -
  • Unomi (unregistered)

    Indeed it is somewhat philosophic or forward-compatible with quantum informatica like someone else mentioned.

    While it can not be defined as TRUE, it is simply FALSE. Who doesn't try to shoot, will always miss. So negative is default here. You can't say, 'Who doesn't try to shoot, will maybe miss'. Simple not true (thus false).

    MAYBE is like 'IT_DEPENDS' or coming to some inner_check_function_wisdom to be called and resulting in either TRUE, FALSE or BOTH. Japanese people could refer to a status called 'MU'..... Not typical programming (thus an anti-pattern).

    CAPTCHA: ewww (indeed, to ugly to even spit on)

    • Unomi -
  • Moose (unregistered)

    I don't see this as a WTF. There are many uses for multi-value logic such as an elevator system.

  • Peter Antoine (unregistered) in reply to Ed Heil
    Ed Heil:
    Dude should be programming Haskell!

    http://www.haskell.org/onlinelibrary/maybe.html

    Lightweights!

    VHDL std_logic, 9 different values for a bit. Two types of maybe, '-' = dont_care and 'X' = unknown.

  • Moose (unregistered)

    I don't see this as a WTF. There are many uses for multi-value logic such as an elevator system.

  • (cs)

    No WTF here !!

    Sorry guys but this is not at all a wtf. Maybe can be seen as a legitimate way to express an "unknown" state and there is at least one language (Magik, see http://en.wikipedia.org/wiki/Magik_%28programming_language%29) that has in is own libraries a 3-state boolean defined as _true, _false and _maybe, with and/or operators that can work with those values.

    Checkboxes, natural choices for a yes/no selection, have 3 states, checked, unchecked and grayed to express the unknown.

    What if you have a boolean property to identify if a user is member of a XYZ association? He may answer you and let you store a Yes or a No in your tables, but if he doesn't want to tell you what are you going to store ...... ? NULL, and also in this case you need the 3rd state.

    MAYBE one day you'll find yourself using a MAYBE...

  • dustin (unregistered)
    Anonymous:
    MAYBE I got the first post

    lol thats pretty funny

  • Winter (unregistered) in reply to mkb
    mkb:
    Winter:
    Did anyone mention FILE_NOT_FOUND yet because I think about 30 more people should post that. Also can we define BRILLANT as well for completeness

    Don't give them ideas. This board doesn't understand the concept of shelflife when applied to injokes.

    3 things I've noticed and stop me from wanting to register to post here:

    "FIRST POST!!11!" occurring for three quarters of the first page of any public discussion

    "The REAL WTF is ____" followed by some extremely dodgy code (usually)

    and then the template posts. (What no FILE_NOT_FOUND?!, Man that sounds like job for PAULA BEAN! etc etc)

    captcha is stinky. Damn right!

  • Jeremy Bettis (unregistered)

    There is a mistake in the commentary. !TRUE cannot equal MAYBE, since !1 = 0 and !2 = 0.

    The right way to evaluate booleans is always if (booleanvar) or if (!booleanvar). Or if someone is feeling pedantic, they could use if (booleanvar == FALSE) and if (booleanvar != FALSE) but they must NEVER do if (booleanvar == TRUE) just in case someone was lazy at some other point and did an assignment like booleanvar = (x != 3) since it might fill in values other than 0 or 1.

  • f@ (unregistered)

    Thank goodness two wrongs don't make a right. But two TRUEs certainly make a MAYBE.

    CAPTCHA: dreadlocks.

  • bobby (unregistered)

    From my past as a database admin and modeler, I'd tend to cast MAYBE as NULL - no value or no state. I've always had to explain the concept of NULL to people as "it's not zero, or MAYBE - it means it has no current state or value, which is different."

    MAYBE implies that it might be TRUE, might be FALSE, might be either-or, might not. That's too ambiguous. The concept of NULL - no current state - fits situations like this pretty well.

  • Kevin (unregistered)
    Anonymous:
    MAYBE I got the first post

    OMG, you did!

  • (cs)

    #define FOURTY_TWO // Fuzzy Logic

  • Earl Colby Pottinger (unregistered)

    The WTF to me is he did not test if 'maybe' existed.

    Most languages will have libraries 'true' and 'false' already defined. If you can't trust the language included defines enough that you have test whether two states exist or not, you should also not be assuming that the define 'maybe' does not already exist.

    Two lines to bullet-proof is all that are needed. The authour clearly knows how and why to do this and still builds a basic assumption into their code that can affect compiling.

  • bpk (unregistered)

    #define YOUR_GUESS_IS_AS_GOOD_AS_MINE 666;

  • bpk (unregistered)

    #define YOUR_GUESS_IS_AS_GOOD_AS_MINE 666;

  • bpk (unregistered)

    #define YOUR_GUESS_IS_AS_GOOD_AS_MINE 666

  • Peter Antoine (unregistered) in reply to Winter
    Winter:
    mkb:
    Winter:
    Did anyone mention FILE_NOT_FOUND yet because I think about 30 more people should post that. Also can we define BRILLANT as well for completeness

    Don't give them ideas. This board doesn't understand the concept of shelflife when applied to injokes.

    3 things I've noticed and stop me from wanting to register to post here:

    "FIRST POST!!11!" occurring for three quarters of the first page of any public discussion

    "The REAL WTF is ____" followed by some extremely dodgy code (usually)

    and then the template posts. (What no FILE_NOT_FOUND?!, Man that sounds like job for PAULA BEAN! etc etc)

    captcha is stinky. Damn right!

    You forgot:

    1. Reading the problem in the wrong language. (i.e. C as C#)
    2. It should have been written in .... (usually Ruby, Python)
    3. Assuming we are all web/database programmers.
  • Jno (unregistered)

    Fer crissakes, it's a missile. Count the letters, and pronounce as two syllables. Miss'eyell. There. Also please refrain from throwing them at friendly military convoys. Thank you.

  • (cs)

    So what exactly does the caller do when the function just shrugs at them? Ask again? (Keep asking in a loop until the universe ends is certainly one classic failure method.) Randomly perturb the input first? Have a SecondOpinion class with alternate implementations of every function? =p

  • Migala (unregistered)

    #define ASK_AGAIN_LATER 111;

  • (cs) in reply to Winter
    Winter:
    3 things I've noticed and stop me from wanting to register to post here:

    "FIRST POST!!11!" occurring for three quarters of the first page of any public discussion

    Maybe if you register and post regularly we can drown out the noise.

  • jonny mnemonic (unregistered) in reply to mkb
    mkb:
    Winter:
    Did anyone mention FILE_NOT_FOUND yet because I think about 30 more people should post that. Also can we define BRILLANT as well for completeness

    Don't give them ideas. This board doesn't understand the concept of shelflife when applied to injokes.

    No quack.

  • kro (unregistered)

    #define's are just plain unsafe use enums, enums, enums, enums

    By the way, I have seen the values of TRUE and FALSE swapped because the code was managing data to inverted logic :) Would like that as an enum or would you just temporarily re-define the #define's ?

  • (cs) in reply to Earl Colby Pottinger
    Earl Colby Pottinger:
    Two lines to bullet-proof is all that are needed. The authour clearly knows how and why to do this and still builds a basic assumption into their code that can affect compiling.

    So the build breaks and you fix it. That's not a very good WTF. It's not insidious at all.

  • (cs) in reply to kro
    kro:
    #define's are just plain unsafe use enums, enums, enums, enums

    #defines, enums, typedefs, and consts all have their pros and cons: 1.) You can only take the address of a const 2.) enums don't have a set value. If you are using them this way (eg enum { FOO = 2, BAR, BAZ}) or casting enums to ints, STOP. 3.) consts and enums cannot be used for macros. 4.) defines don't have a type, which is more risky than const int, const short, const unsigned int64_t 5.) #define where a typedef should be used is just stupid. I've never seen this, though.

  • (cs)

    For those that don't know (obviously the OP), there ARE three values for geometric intersections when it comes to 3D math:

    • Intersects
    • Does not intersect
    • Touches (yes, this is different than Intersects)

    The WTF here is of course the lack of checking for MAYBE, besides the name of the define.

  • diaphanein (unregistered) in reply to mkb

    boost has a pretty nice 3-state boolean lib:

    http://www.boost.org/doc/html/tribool.html

  • Pon (unregistered)

    Hasn't anyone here heard of Fuzzy Logic?

    It's one of the most useful tools in AI, robotics, and other such fields.

    It's similiar to probability, just instead of events occuring, it's about membership in sets.

    For example, I'd be 75% child and 50% adult.

  • Kalinka (unregistered)

    Not a WTF.

    When doing geometric intersections you usually first test against a bounding volume (bounding box, bounding sphere) or use some other quick-check.

    The values then correspond to:

    TRUE = shapes definitely intersect MAYBE = bounding volumes definitely intersect, shapes may or may not FALSE = shapes definitely do not intersect

    Can we please have WTFs posted by people who can actually spot them? So far it seems like WTFs are "what some junior-junior-newbie-temp worker doesn't understand and therefore calls a WTF with no attempt at all to understand", or general whining of the type "My stupid boss says 2+2=5, WTF!"

    True WTFs are much more subtle. They are not caused by stupidity, nor by ignorance. They are when perfectly rational people do what is perfectly rational at the time - with no deadlines and stupid bosses - but which turns out to be completely wrong in retrospect.

    I know, because I have at least a dozen of them to my name.

  • DmR (unregistered) in reply to jo42

    #define FOURTY_TWO //Crappy spelling

    captcha: riaa - really idiotic, always a-holes

  • merreborn's nemesis (unregistered)

    Seriously, using #define to redefine true and false is just stupid. The programmer should just have to return true, false, or (as seems to be needed here) an enum value.

    enum { Intersects, Tangent, Disjoint };

    CAPTCHA: tesla...as in shockingly bad code

Leave a comment on “Rarely Just TRUE or FALSE”

Log In or post as a guest

Replying to comment #117838:

« Return to Article