- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
That's one way to make sure people don't change default settings ^^
Admin
pure genius :D
Admin
A nice WTF. Good find!
Admin
The logic is perfect, it's so beguiling!
Admin
so somebody thought #define would work at runtime? (Sorry I am a java idiot!)
Admin
Skizz
Admin
Exactly, he/she thought # statements (precompiler directives) work at runtime, but obviously they do not :)
Admin
I get it!
They forgot the part that generated new code with switched #defines, compiled it and reran the executable.
Admin
holy crap.
Admin
I'd love to see the output of "svn blame" for that.
Admin
That is a very nice one.
Admin
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!
Admin
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)
Admin
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).
Admin
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?!
Admin
Easy fix: implement dynamic recompilation.
Admin
PHP is different, actually... define() is executed at run time, but PHP constants can't be redefined.
Admin
Admin
Best CodeSOD we've had in ages!
Admin
I too have used the precompiler for certain static computations, but never quite like this...
Admin
:O
Sorry to break it to you, but
The toggles... they do nothing
Admin
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.
Admin
Fear not: runkit_constant_redefine
Admin
Jiminy Jillikers!
Admin
brilliant!
next wtf: captcha - transverbero
Admin
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
Admin
Oh okay, now it made sense. Thanks.
Admin
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!
Admin
A red bool to a stag you say? I'd rather give a redbull to a fag.
Admin
Admin
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.
Admin
Why do you say that MFC is "legacy"? It is still being used a lot even in new programs.
Admin
The Real RWTF is that you don't know what you are saying with "C changes it's own code"
Admin
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.
Admin
Admin
Made of win!
Admin
Back to sleep. The stars are not yet right for you.
Admin
Its Brillant you n00b!
Admin
Admin
Admin
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.
Admin
You've misspelled 'Brillant' there. :)
Admin
Admin
bows in respect
Admin
Probably thinking of the next status update...
Captcha - illum: To make them all sick.
Admin
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; }
Admin
This is the best WTF I've seen in at least 6 months, LOVE it!
Admin
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?
Admin
No, no, no, it would return the string "Brillant" :-)
Admin
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...