Comment On The Toggle that Wouldn't

"I work for a software development house that creates business software, maintaining legacy MFC applications," Graf writes. "We recently received an issue where a filter-toggle wouldn't switch back and forth, never changing from its default value. It's was a small utility function, rarely used, so we were a bit surprised to see it come up. Taking a quick glance at the code revealed the following: [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: The Toggle that Wouldn't

2008-11-13 08:02 • by Sander (unregistered)
That's one way to make sure people don't change default settings ^^

Re: The Toggle that Wouldn't

2008-11-13 08:04 • by lx (unregistered)
pure genius :D

Re: The Toggle that Wouldn't

2008-11-13 08:05 • by JimmyVile (unregistered)
A nice WTF. Good find!

Re: The Toggle that Wouldn't

2008-11-13 08:06 • by xan
The logic is perfect, it's so beguiling!

Re: The Toggle that Wouldn't

2008-11-13 08:09 • by java ignorant (unregistered)
so somebody thought #define would work at runtime? (Sorry I am a java idiot!)

Re: The Toggle that Wouldn't

2008-11-13 08:09 • by Skizz
228825 in reply to 228823
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

Re: The Toggle that Wouldn't

2008-11-13 08:12 • by blabla (unregistered)
228826 in reply to 228824
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 :)

Re: The Toggle that Wouldn't

2008-11-13 08:14 • by Jurgen (unregistered)
I get it!

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

Re: The Toggle that Wouldn't

2008-11-13 08:15 • by gosse (unregistered)
holy crap.

Re: The Toggle that Wouldn't

2008-11-13 08:21 • by Jeroen (unregistered)
I'd love to see the output of "svn blame" for that.

Re: The Toggle that Wouldn't

2008-11-13 08:25 • by Mark V Shaney (unregistered)
That is a very nice one.

Re: The Toggle that Wouldn't

2008-11-13 08:30 • by JimM
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!

Re: The Toggle that Wouldn't

2008-11-13 08:33 • by 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)

Re: The Toggle that Wouldn't

2008-11-13 08:41 • by 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).

Re: The Toggle that Wouldn't

2008-11-13 08:45 • by 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?!

Re: The Toggle that Wouldn't

2008-11-13 08:49 • by Matt (unregistered)
Easy fix: implement dynamic recompilation.

Re: The Toggle that Wouldn't

2008-11-13 08:51 • by srednitsa (unregistered)
228838 in reply to 228836
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.

Re: The Toggle that Wouldn't

2008-11-13 08:51 • by Dirk Diggler (unregistered)
228839 in reply to 228835
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.

Re: The Toggle that Wouldn't

2008-11-13 08:52 • by tlg
Best CodeSOD we've had in ages!

Re: The Toggle that Wouldn't

2008-11-13 08:55 • by snoofle
228842 in reply to 228824
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...

Re: The Toggle that Wouldn't

2008-11-13 08:56 • by abx
:O

Sorry to break it to you, but

The toggles... they do nothing

Re: The Toggle that Wouldn't

2008-11-13 08:57 • by Glenn Lasher (unregistered)
228844 in reply to 228831
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.

Re: The Toggle that Wouldn't

2008-11-13 09:00 • by M (unregistered)
228845 in reply to 228838
> define() is executed at run time, but PHP constants can't be redefined.

Fear not: runkit_constant_redefine

Re: The Toggle that Wouldn't

2008-11-13 09:03 • by Cuncator (unregistered)
228846 in reply to 228843
Jiminy Jillikers!

Re: The Toggle that Wouldn't

2008-11-13 09:04 • by some coder (unregistered)
228847 in reply to 228843
abx:
:O

Sorry to break it to you, but

The toggles... they do nothing


brilliant!

next wtf: captcha - transverbero

Re: The Toggle that Wouldn't

2008-11-13 09:15 • by Sean (unregistered)
228850 in reply to 228832
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

Re: The Toggle that Wouldn't

2008-11-13 09:18 • by jordanwb (unregistered)
228851 in reply to 228826
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.

Re: The Toggle that Wouldn't

2008-11-13 09:25 • by 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!

Re: The Toggle that Wouldn't

2008-11-13 09:30 • by mauhiz (unregistered)
228855 in reply to 228835
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.

Re: The Toggle that Wouldn't

2008-11-13 09:33 • by m0ffx (unregistered)
228856 in reply to 228843

Re: The Toggle that Wouldn't

2008-11-13 09:33 • by Vechni
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.

Re: The Toggle that Wouldn't

2008-11-13 09:35 • by beeblebrox (unregistered)
228858 in reply to 228820
Why do you say that MFC is "legacy"? It is still being used a lot even in new programs.

Re: The Toggle that Wouldn't

2008-11-13 09:37 • by Albert Turing (unregistered)
228859 in reply to 228853
The Real RWTF is that you don't know what you are saying with "C changes _it's own_ code"

Re: The Toggle that Wouldn't

2008-11-13 09:40 • by Albert Turing (unregistered)
228861 in reply to 228832
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.

Re: The Toggle that Wouldn't

2008-11-13 09:40 • by starlite (unregistered)
228862 in reply to 228843
abx:

The toggles... they do nothing

best comment ever!

Re: The Toggle that Wouldn't

2008-11-13 09:51 • by teh_n1gz (unregistered)
228864 in reply to 228843
abx:
:O

Sorry to break it to you, but

The toggles... they do nothing


Made of win!

Re: The Toggle that Wouldn't

2008-11-13 09:54 • by Shubb Niggurath (unregistered)
228866 in reply to 228835
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.

Re: The Toggle that Wouldn't

2008-11-13 10:10 • by Rachelle (unregistered)
228868 in reply to 228835
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!

Re: The Toggle that Wouldn't

2008-11-13 10:11 • by Code Dependent
228869 in reply to 228835
cthulhu:
Possibly this will continue with such wit as suggesting the function also return the string "Brilliant!".
Such a brillant observation.

Re: The Toggle that Wouldn't

2008-11-13 10:12 • by Code Dependent
228870 in reply to 228843
abx:
:O

Sorry to break it to you, but

The toggles... they do nothing
Good one! Roffle mayo!

Re: The Toggle that Wouldn't

2008-11-13 10:13 • by SuperousOxide
228871 in reply to 228858
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.

Re: The Toggle that Wouldn't

2008-11-13 10:14 • by heltoupee
228872 in reply to 228835
cthulhu:

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


You've misspelled 'Brillant' there. :)

Re: The Toggle that Wouldn't

2008-11-13 10:20 • by Woosh! (unregistered)
228874 in reply to 228861
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?

Re: The Toggle that Wouldn't

2008-11-13 10:26 • by Andrew (unregistered)
228875 in reply to 228843
abx:
The toggles... they do nothing


*bows in respect*

Re: The Toggle that Wouldn't

2008-11-13 10:34 • by Charles (unregistered)

Probably thinking of the next status update...

Captcha - illum: To make them all sick.

Re: The Toggle that Wouldn't

2008-11-13 10:43 • by Niels (unregistered)
228880 in reply to 228824
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;
}

Re: The Toggle that Wouldn't

2008-11-13 10:44 • by AvidReader (unregistered)
This is the best WTF I've seen in at least 6 months, LOVE it!

Re: The Toggle that Wouldn't

2008-11-13 10:55 • by 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?

Re: The Toggle that Wouldn't

2008-11-13 10:56 • by tbrown (unregistered)
228883 in reply to 228835
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" :-)

Re: The Toggle that Wouldn't

2008-11-13 10:59 • by rmz (unregistered)
228884 in reply to 228882
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...
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment