• Sander (unregistered)

    That's one way to make sure people don't change default settings ^^

  • lx (unregistered)

    pure genius :D

  • JimmyVile (unregistered)

    A nice WTF. Good find!

  • (cs)

    The logic is perfect, it's so beguiling!

  • java ignorant (unregistered)

    so somebody thought #define would work at runtime? (Sorry I am a java idiot!)

  • (cs) in reply to xan
    xan:
    The logic is perfect, it's so beguiling!
    I'm sorry, but perfection can only be achieved through use of a wooden table.

    Skizz

  • blabla (unregistered) in reply to java ignorant
    java ignorant:
    so somebody thought #define would work at runtime? (Sorry I am a java idiot!)

    Exactly, he/she thought # statements (precompiler directives) work at runtime, but obviously they do not :)

  • Jurgen (unregistered)

    I get it!

    They forgot the part that generated new code with switched #defines, compiled it and reran the executable.

  • gosse (unregistered)

    holy crap.

  • Jeroen (unregistered)

    I'd love to see the output of "svn blame" for that.

  • Mark V Shaney (unregistered)

    That is a very nice one.

  • (cs)

    I call shenanigans: this is a clear, indisputable WTF; it's actually amusing to coders with only basic experience of the language (my C / C++ got as far as 'Hello World!'); and it is concise and well-written.

    It's far too good a quality article to be genuine!

  • ath (unregistered)

    That's not a WTF. Using the pre-compiler for calculations is a common technique in libraries such as boost.

    Just tell the customer to recompile and define/undefine ENABLE_FILTER whenever (s)he wants to switch. Sure, it's a bit inconvenient but it gives you blazingly fast execution speed! (Oh, and simple gui since you can remove all buttons)

  • cthulhu (unregistered)

    I notice this article contains a function returning a bool.

    To certain DailyWTF readers this is like a red flag to a bull. How many of them are itching their fingers to get off the first predictably lame comment that IsFilterEnabled() does not also return FileNotFound? Someone may even rewrite the function to that effect.

    Possibly this will continue with such wit as suggesting the function also return the string "Brilliant!".

    If only I too could find such desperate links between Stuff Happening Now and Stuff That Happened In The Past, perhaps then I could be the first to respond (or "fist" as the commenters in question are prone to say).

  • Nothrem Sinsky (unregistered)

    Well, I've seen lots of those in PHP; like this one:

    <?php define('GOTO_PAGE', 'error'); if (null != $_GET['page']) define('GOTO_PAGE', $_GET['page']); //... ?>

    Why am I always getting the error page?!

  • Matt (unregistered)

    Easy fix: implement dynamic recompilation.

  • srednitsa (unregistered) in reply to Nothrem Sinsky
    Nothrem Sinsky:
    Well, I've seen lots of those in PHP; like this one: <?php define('GOTO_PAGE', 'error'); if (null != $_GET['page']) define('GOTO_PAGE', $_GET['page']); //... ?>

    Why am I always getting the error page?!

    PHP is different, actually... define() is executed at run time, but PHP constants can't be redefined.

  • Dirk Diggler (unregistered) in reply to cthulhu
    cthulhu:
    I notice this article contains a function returning a bool.

    To certain DailyWTF readers this is like a red flag to a bull. How many of them are itching their fingers to get off the first predictably lame comment that IsFilterEnabled() does not also return FileNotFound? Someone may even rewrite the function to that effect.

    Possibly this will continue with such wit as suggesting the function also return the string "Brilliant!".

    If only I too could find such desperate links between Stuff Happening Now and Stuff That Happened In The Past, perhaps then I could be the first to respond (or "fist" as the commenters in question are prone to say).

    Change 'brilliant' to 'brillant' and Bob's your uncle, you're done.
  • (cs)

    Best CodeSOD we've had in ages!

  • (cs) in reply to java ignorant
    java ignorant:
    so somebody thought #define would work at runtime? (Sorry I am a java idiot!)
    Fairly clear as this is not java....

    I too have used the precompiler for certain static computations, but never quite like this...

  • (cs)

    :O

    Sorry to break it to you, but

    The toggles... they do nothing

  • Glenn Lasher (unregistered) in reply to JimM
    I call shenanigans: . . . it is concise and well-written.

    Let me draw an analogy.

    A director can make a movie. It can be shot in IMAX; film, not digital; with the obligatory 48 fps frame rate for silky-smooth motion, and the enormous frames that this film format entails; accompany it with the obligatory umpteen-gajillion channels of 24-bit high-sample-rate linear PCM audio, hiring only the best and the brightest of crew . . . but still have a lousy script. It will look and sound gorgeous, but still be a turkey.

  • M (unregistered) in reply to srednitsa

    define() is executed at run time, but PHP constants can't be redefined.

    Fear not: runkit_constant_redefine

  • Cuncator (unregistered) in reply to abx

    Jiminy Jillikers!

  • some coder (unregistered) in reply to abx
    abx:
    :O

    Sorry to break it to you, but

    The toggles... they do nothing

    brilliant!

    next wtf: captcha - transverbero

  • Sean (unregistered) in reply to ath
    ath:
    That's not a WTF. Using the pre-compiler for calculations is a common technique in libraries such as boost.

    Just tell the customer to recompile and define/undefine ENABLE_FILTER whenever (s)he wants to switch. Sure, it's a bit inconvenient but it gives you blazingly fast execution speed! (Oh, and simple gui since you can remove all buttons)

    I really don't know why everything isn't 100% hard coded using defines. Giving the user dynamic choices at run time leads to slow code, large executables, and annoying debugging. Instead if #define is used to its true potential all executables would just be single path execution with not annoying branches.

    I say we start a programming revolution to get back to the way things should be. If you want to say no to a dialog box well you better figure that out before you go ahead and compile the exe

  • jordanwb (unregistered) in reply to blabla
    blabla:
    java ignorant:
    so somebody thought #define would work at runtime? (Sorry I am a java idiot!)

    Exactly, he/she thought # statements (precompiler directives) work at runtime, but obviously they do not :)

    Oh okay, now it made sense. Thanks.

  • Alonzo Turing (unregistered)

    The real WTF: That C uses another language to change it's own code. And if you like c++, you even get another one! For free!

  • mauhiz (unregistered) in reply to cthulhu
    cthulhu:
    I notice this article contains a function returning a bool.

    To certain DailyWTF readers this is like a red flag to a bull.

    A red bool to a stag you say? I'd rather give a redbull to a fag.

  • m0ffx (unregistered) in reply to abx
  • (cs)

    What is so LOLOLOLOL EPIC WTF about a programmer fluent in ____ language writing C++ ? This is pretty common/mundane. Does the level of epicness derive from this being a SOD that most here actually comprehend, because I think that's exactly the kind of shenanigans that are going on.

  • beeblebrox (unregistered) in reply to Sander

    Why do you say that MFC is "legacy"? It is still being used a lot even in new programs.

  • Albert Turing (unregistered) in reply to Alonzo Turing

    The Real RWTF is that you don't know what you are saying with "C changes it's own code"

  • Albert Turing (unregistered) in reply to ath
    ath:
    That's not a WTF. Using the pre-compiler for calculations is a common technique in libraries such as boost.

    The problem is that while there is a function "Toggle()" which is supposed to somehow "toggle" something at runtime, it is really a no-op and doesn't toggle anything at all. The Toggling could as well happen 1000 lines below the function corpse and nothing would change.

  • starlite (unregistered) in reply to abx
    abx:
    The toggles... they do nothing
    best comment ever!
  • teh_n1gz (unregistered) in reply to abx
    abx:
    :O

    Sorry to break it to you, but

    The toggles... they do nothing

    Made of win!

  • Shubb Niggurath (unregistered) in reply to cthulhu
    cthulhu:
    I notice this article contains a function returning a bool.

    To certain DailyWTF readers this is like a red flag to a bull. How many of them are itching their fingers to get off the first predictably lame comment that IsFilterEnabled() does not also return FileNotFound? Someone may even rewrite the function to that effect.

    Possibly this will continue with such wit as suggesting the function also return the string "Brilliant!".

    If only I too could find such desperate links between Stuff Happening Now and Stuff That Happened In The Past, perhaps then I could be the first to respond (or "fist" as the commenters in question are prone to say).

    Back to sleep. The stars are not yet right for you.

  • Rachelle (unregistered) in reply to cthulhu
    cthulhu:
    I notice this article contains a Possibly this will continue with such wit as suggesting the function also return the string "Brilliant!".

    Its Brillant you n00b!

  • (cs) in reply to cthulhu
    cthulhu:
    Possibly this will continue with such wit as suggesting the function also return the string "Brilliant!".
    Such a brillant observation.
  • (cs) in reply to abx
    abx:
    :O

    Sorry to break it to you, but

    The toggles... they do nothing

    Good one! Roffle mayo!

  • (cs) in reply to beeblebrox
    beeblebrox:
    Why do you say that MFC is "legacy"? It is still being used a lot even in new programs.

    He's not saying MFC is legacy, he's saying these apps are legacy. They're no longer being actively developed, they just get called in for some spot fixes on them.

  • (cs) in reply to cthulhu
    cthulhu:
    Possibly this will continue with such wit as suggesting the function also return the string "Brilliant!".

    You've misspelled 'Brillant' there. :)

  • Woosh! (unregistered) in reply to Albert Turing
    Albert Turing:
    ath:
    That's not a WTF. Using the pre-compiler for calculations is a common technique in libraries such as boost.

    The problem is that while there is a function "Toggle()" which is supposed to somehow "toggle" something at runtime, it is really a no-op and doesn't toggle anything at all. The Toggling could as well happen 1000 lines below the function corpse and nothing would change.

    A good morning to you. Maybe have some breakfast before commenting?

  • Andrew (unregistered) in reply to abx
    abx:
    The toggles... they do nothing

    bows in respect

  • Charles (unregistered)

    Probably thinking of the next status update...

    Captcha - illum: To make them all sick.

  • Niels (unregistered) in reply to java ignorant

    Yeah, the #define in c/c++ are actually pre-compile time text processing. So this code will look something like this the moment it is actually offered fed into the compiler:

    void CReport::ToggleFilter() { }

    bool CReport::IsFilterEnabled() { return true; }

  • AvidReader (unregistered)

    This is the best WTF I've seen in at least 6 months, LOVE it!

  • Matt (unregistered)

    I can understand someone making this mistake, but why didn't that person test what they wrote? Why didn't Q&A catch it either?

  • tbrown (unregistered) in reply to cthulhu
    cthulhu:
    I notice this article contains a function returning a bool.

    To certain DailyWTF readers this is like a red flag to a bull. How many of them are itching their fingers to get off the first predictably lame comment that IsFilterEnabled() does not also return FileNotFound? Someone may even rewrite the function to that effect.

    Possibly this will continue with such wit as suggesting the function also return the string "Brilliant!".

    If only I too could find such desperate links between Stuff Happening Now and Stuff That Happened In The Past, perhaps then I could be the first to respond (or "fist" as the commenters in question are prone to say).

    No, no, no, it would return the string "Brillant" :-)

  • rmz (unregistered) in reply to Matt

    I don't know, but I would contend that a question-and-answer session is not a very efficient way to find bugs in code...

Leave a comment on “The Toggle that Wouldn't”

Log In or post as a guest

Replying to comment #228840:

« Return to Article