- 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
Magnificent!
Admin
For those who don't see the wtf, look at the parameters of this function: http://www.cplusplus.com/reference/clibrary/cstdlib/itoa.html
Admin
Did someone notice there was a constant defined as 10 and use that without considering that something called VERSION_CODE would probably change, or did they just define their own variable for this function but stupidly call it VERSION_CODE - whereupon subsequent coders incremented it, because they thought they should?
Admin
Fixed..
Admin
Sticking to the rule that magic numbers are bad, I propose that the code is fixed like this:
Admin
This is why you should always pay attention to context when doing a search/replace to get rid of magic numbers.
I guess they can't say that nobody writes WTFs in base 13.
Admin
I look forward to when everyone uses hex in 2011.
Admin
Ah. An Honest WTF that is the real WTF.
Also, I like the AD at the top of the page: Non-WTF Job: Want a 30 inch monitor? Work for TripAdvisor (Newton, MA)
Are we that easily swayed? COURSE NOT! Make it 32 and you have a deal.
Admin
"This one goes to base 11"
Admin
One other possibility is that the original code had the 10 hardcoded there in the itoa. But ALSO that the real version code value "10" was also everywhere else in the code.
Then someone other (possibly an intern) refactor the 10s to replace them with VERSION_CODE for easier management of their version. Using a quick search/replace in the code base, you cause no trouble. Hey! its exactly the same code (possibly even byte-to-byte identical) just that 10s have now been replaced with VERSION_CODE.
Thus, the WTF does not incumb to the original developer, but the one who refactor the code.
If in the first place the orginal developper had use an ITOA_BASE_CONVERSION constant instead, it might have raised some alarms bells to read "#define ITOA_BASE_CONVERSION VERSION_CODE". But, that assumes the refactoring developper reviewed its changes.
Admin
Really the original developer should have made this configurable, and used lots of words like 'Factory' to construct the numeric representations... that's the real WTF... if you're going to be configurable you may as well go all the way.
Admin
This reminds me of one bug I fixed which occurred on Wednesdays. The code was something like (it was in Java):
When I asked the dev who had checked it in, he said he was testing something & forgot to take it out. We still got a laugh out of it, though.
Admin
Brilliant!
Admin
{Oh, I have a large monitor too}
Admin
CAPTCHA: eros (how did it know?)
Admin
Admin
Don't be ridickulous.
Admin
You're planning on being alive for another 1839 years?
Admin
I remember seeing this already. TRWTF is that you are lazy.
CAPTCHA: refoveo
Admin
Well, found a nice function in the code I currently work with:
bool IsNegative(double value);
I bet you can image how the body of that function looks. And somehow it is a member function and not even static. Well... better to be on the save side, perhaps the definition of negative may change!
Admin
Looks to me like a Jr. developer, fresh out of "Magic Numbers Are EVIL! Take my word for it because I am a professor that never did any real software development" college, saw that "10" was used in the call to itoa(...), found a #define that matched it, and simply changed the 10 to the #defined value.
I have seen dumber things done to existing codebases...
Capcha: dolor -- a dull color maybe?
Admin
I bet the following: bool IsNegative(double value) { if (value < 0.0) return true; else if (value >= 0.0) return false; else return FILE_NOT_FOUND; { right?
Admin
All your base 13 are belong to us!
Admin
Look, the author of itoa was doing a good thing by conserving variables and re-using existing code instead of inventing a whole new variable to store the number 10. If you can't see that, then you just dont understand reusable programming.
The only WTF is the author of itoa did not put the required comment after the definition of VERSION_CODE, so future developers would know where it is used, like this:
#define VERSION_CODE 10 //2005 // Used in the following modules: // xxx.c, line 105 // yyy.c, line 1498 // etc, you get the picture
Admin
Admin
I think you forgot to stamp "Best of the Sidebar" on this one.
http://forums.thedailywtf.com/forums/t/8491.aspx
(Now let's brace ourselves, for another resurrected thread will pop up.)
Admin
Anyway, it's still faster doing a search for VERSION_CODE, with the IDE sending you to the proper line, than manually going to line 105 of xxx.c
Admin
Ad? What ad?
//Firefox+Adblock
Admin
Isn't there an overload of itoa that doesn't take any base argument at all (and defaults to base10)? I mean, 9 times out of 10 that's what you want anyway?
Admin
Admin
Wow, that's quite a gem. We need more stories like this.
Admin
I remember reading this already. You're an idiot.
You're also a moron for quoting your CAPTCHA.
Admin
I didn't even know that there was a third parameter to itoa() in the first place. Why?
Using itoa() at all is a bit of a WTF in itself. It's not like it does anything that sprintf() doesn't do (apart from print numbers in base 13, obviously), and it certainly does a lot less.
I shudder to imagine an internationalisation wrapper around this thing that tries to deal with dates, currencies, and the like through repeated bludgeoning with an insane third parameter.
Admin
You can admit that with a lisp, if you like.
Admin
All your base are increment by us.
Admin
itoa() and ltoa() are non-standard library functions, and that is a real WTF. For portability reasons they shouldn't be used, as not all compilers support them.
Admin
Admin
That's what SHE said!
Admin
Admin
Funniest WTF I've read all year!
Admin
Admin
I'll never make fun of...
#define BASE_TEN 10
... again. It is obviously armor plating the code against cow orkers.
Admin
Hey lay off, at least this one contains some code, and not just exciting stories about servers being used to run Quake.
Admin
Do I understand that this program, whatever it is, gave wrong answers for 2+ years before anyone looked for a bug?
WTF!
Admin
Actually, this one is right under the logo and gets past Adblock for me, but isn't obtrusive so I don't care.
I've actually unblocked ads for TDWTF at various times because of Beanbag Girl and Irish Girl.
Admin
Talk to your local pastor, and avoid psychiatrists and crossing the road.
I know these things.
Admin
Admin
Admin
True, as it's a macro.
Admin
That's what we call Canadian dollars eh.