Comment On It Gets Worse Each Year

"A while back," Steven Victor wrote, "I was asked to look at an issue where numerical data 'kept getting more and more inaccurate' in newer versions of a software product." [expand full text]
« PrevPage 1 | Page 2Next »

Re: It Gets Worse Each Year

2008-06-18 08:03 • by Tim the Enchanter (unregistered)
Magnificent!

Re: It Gets Worse Each Year

2008-06-18 08:14 • by Michael (unregistered)
For those who don't see the wtf, look at the parameters of this function:
http://www.cplusplus.com/reference/clibrary/cstdlib/itoa.html

Re: It Gets Worse Each Year

2008-06-18 08:17 • by Dave (unregistered)
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?

Re: It Gets Worse Each Year

2008-06-18 08:19 • by Grovesy
200744 in reply to 200741
Fixed..


//#define VERSION_CODE 10 //2005
//#define VERSION_CODE 11 //1564
//#define VERSION_CODE 12 //11B3
#define VERSION_CODE 13 //BB6

Re: It Gets Worse Each Year

2008-06-18 08:19 • by #define AUTHOR_NAME 13 (unregistered)
Sticking to the rule that magic numbers are bad, I propose that the code is fixed like this:


#define VERSION_CODE 13 //2008
#define VERSION_CODE_OFFSET -3 //2005-2008

itoa(typelib_version, sTypelib_version, VERSION_CODE + VERSION_CODE_OFFSET);

Re: It Gets Worse Each Year

2008-06-18 08:20 • by NSCoder
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.

Re: It Gets Worse Each Year

2008-06-18 08:22 • by corey (unregistered)
I look forward to when everyone uses hex in 2011.

Re: It Gets Worse Each Year

2008-06-18 08:23 • by NaN
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.

Re: It Gets Worse Each Year

2008-06-18 08:35 • by gabba
"This one goes to base 11"

Re: It Gets Worse Each Year

2008-06-18 08:35 • by philibert (unregistered)
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.

Re: It Gets Worse Each Year

2008-06-18 08:39 • by Grovesy
200752 in reply to 200751
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.

Re: It Gets Worse Each Year

2008-06-18 08:40 • by fountainer (unregistered)
This reminds me of one bug I fixed which occurred on Wednesdays. The code was something like (it was in Java):
if((new Calendar()).get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) {

// Set some variable
}


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.

Re: It Gets Worse Each Year

2008-06-18 08:57 • by Alan (unregistered)
200756 in reply to 200750
gabba:
"This one goes to base 11"

I was thinking the *exact same thing*

Brilliant!

Re: It Gets Worse Each Year

2008-06-18 09:01 • by ParkinT
200758 in reply to 200748
NaN:
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.

Mine is already 32 inches!

{Oh, I have a large monitor too}

Re: It Gets Worse Each Year

2008-06-18 09:15 • by #define AUTHOR_NAME 13 (unregistered)
200760 in reply to 200758
ParkinT:

Mine is already 32 inches!

Mine is VERSION_CODE inches!
(it gets bigger every year)


CAPTCHA: eros (how did it know?)

Re: It Gets Worse Each Year

2008-06-18 09:18 • by Anon. (unregistered)
200761 in reply to 200750
gabba:
"This one goes to base 11"

Nobody makes jokes in base 13.

Re: It Gets Worse Each Year

2008-06-18 09:24 • by dave (unregistered)
200763 in reply to 200758
Don't be ridickulous.

Re: It Gets Worse Each Year

2008-06-18 09:35 • by Markp
200765 in reply to 200747
corey:
I look forward to when everyone uses hex in 2011.


You're planning on being alive for another 1839 years?

Re: It Gets Worse Each Year

2008-06-18 09:36 • by WTF? (unregistered)
I remember seeing this already. TRWTF is that you are lazy.

CAPTCHA: refoveo

Re: It Gets Worse Each Year

2008-06-18 09:41 • by Vollhorst (unregistered)
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!

Re: It Gets Worse Each Year

2008-06-18 09:44 • by James R. Twine (unregistered)
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?

Re: It Gets Worse Each Year

2008-06-18 09:54 • by sysKin (unregistered)
200770 in reply to 200767
Vollhorst:
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.


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?

Re: It Gets Worse Each Year

2008-06-18 09:55 • by KattMan
200771 in reply to 200761
Anon.:
gabba:
"This one goes to base 11"

Nobody makes jokes in base 13.


All your base 13 are belong to us!

This is reusable code

2008-06-18 10:01 • by Top Cod3r (unregistered)
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

Re: It Gets Worse Each Year

2008-06-18 10:02 • by Doc Monster (unregistered)
200773 in reply to 200768
James R. Twine:
Capcha: dolor -- a dull color maybe?

"Pain" in Spanish.

Re: It Gets Worse Each Year

2008-06-18 10:09 • by Spectre
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.)

Re: This is reusable code

2008-06-18 10:10 • by nimis (unregistered)
200777 in reply to 200772
Top Cod3r:
#define VERSION_CODE 10 //2005
// Used in the following modules:
// xxx.c, line 105
// yyy.c, line 1498
// etc, you get the picture

And you can't use the VERSION_CODE variable anywhere if it isn't commented before there. And as you're trying to modify a header, you can only edit it with permission from management.
Please notice that you also need permission to insert a line below 1498 at yyy.c Long live to long lines!

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

Re: It Gets Worse Each Year

2008-06-18 10:14 • by Ozymandias (unregistered)
200781 in reply to 200748
Ad? What ad?

//Firefox+Adblock

Re: It Gets Worse Each Year

2008-06-18 10:14 • by James (unregistered)
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?

Re: It Gets Worse Each Year

2008-06-18 10:33 • by Generic Phil (unregistered)
200795 in reply to 200782
James:
I mean, 9 times out of 10 that's what you want anyway?
That's very true; half the time I'm working in base 18.

Re: It Gets Worse Each Year

2008-06-18 10:53 • by WC (unregistered)
Wow, that's quite a gem. We need more stories like this.

Re: It Gets Worse Each Year

2008-06-18 10:57 • by KenW
200812 in reply to 200766
WTF?:
I remember seeing this already. TRWTF is that you are lazy.

CAPTCHA: refoveo


I remember reading this already. You're an idiot.

You're also a moron for quoting your CAPTCHA.

Re: It Gets Worse Each Year

2008-06-18 11:01 • by real_aardvark
200817 in reply to 200742
Michael:
For those who don't see the wtf, look at the parameters of
the itoa function
Pardon my anal fix, as they say.

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.

Re: It Gets Worse Each Year

2008-06-18 11:04 • by real_aardvark
200822 in reply to 200776
Spectre:
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.)
Well, ya gotta admit, it is pithy.

You can admit that with a lisp, if you like.

Re: It Gets Worse Each Year

2008-06-18 11:06 • by mtu (unregistered)
All your base are increment by us.

Re: It Gets Worse Each Year

2008-06-18 11:07 • by mrprogguy
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.

Re: This is reusable code

2008-06-18 11:26 • by Mark (unregistered)
200840 in reply to 200777
Anyway, it's still faster doing a search for VERSION_CODE, with the IDE...
I'd rather use xemacs and start a holy editor war! Give me:
  M-x grep VERSION_CODE $(find . -name "*.[ch]")
or give me death^H^H^H^H^Ha really big monitor!

Re: It Gets Worse Each Year

2008-06-18 11:26 • by A Nonny Mouse (unregistered)
200842 in reply to 200817
real_aardvark:
Pardon my anal fix, as they say.


That's what SHE said!

Re: This is reusable code

2008-06-18 11:38 • by Zonkers
200854 in reply to 200840
Mark:
Anyway, it's still faster doing a search for VERSION_CODE, with the IDE...
I'd rather use xemacs and start a holy editor war! Give me:
  M-x grep VERSION_CODE $(find . -name "*.[ch]")
or give me death^H^H^H^H^Ha really big monitor!

Screw that, I'd rather use vim.
  :!grep VERSION_CODE $(find . -name "*.[ch]")

Re: It Gets Worse Each Year

2008-06-18 11:59 • by foo (unregistered)
Funniest WTF I've read all year!

Re: It Gets Worse Each Year

2008-06-18 12:01 • by AssimilatedByBorg
200868 in reply to 200761
Anon.:

Nobody makes jokes in base 13.

I would have, 5 days ago, on Friday the 10th, if only I had thought of it at the time... :)

Re: It Gets Worse Each Year

2008-06-18 12:03 • by foo (unregistered)
200871 in reply to 200746
This is why you should always pay attention to context when doing a search/replace to get rid of magic numbers.


I'll never make fun of...

#define BASE_TEN 10

... again. It is obviously armor plating the code against cow orkers.

Re: It Gets Worse Each Year

2008-06-18 12:04 • by Bobbo (unregistered)
200872 in reply to 200776
Spectre:
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.)


Hey lay off, at least this one contains some code, and not just exciting stories about servers being used to run Quake.

Re: It Gets Worse Each Year

2008-06-18 12:14 • by Nutmeg Programmer (unregistered)
Do I understand that this program, whatever it is, gave wrong answers for 2+ years before anyone looked for a bug?

WTF!

Re: It Gets Worse Each Year

2008-06-18 12:16 • by Mr Ascii
200886 in reply to 200781
Ozymandias:
Ad? What ad?

//Firefox+Adblock

I've keep hearing about ads on the Internet too.

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.

Re: It Gets Worse Each Year

2008-06-18 12:39 • by real_aardvark
200916 in reply to 200842
A Nonny Mouse:
real_aardvark:
Pardon my anal fix, as they say.


That's what SHE said!
Y'know, I worry about you. That's just me, I guess.

Talk to your local pastor, and avoid psychiatrists and crossing the road.

I know these things.

Re: It Gets Worse Each Year

2008-06-18 12:41 • by real_aardvark
200918 in reply to 200782
James:
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?
...

Re: It Gets Worse Each Year

2008-06-18 14:30 • by Ilya Ehrenburg (unregistered)
200967 in reply to 200812
KenW:
You're also a moron for quoting your CAPTCHA.

Could it be you should reconsider your notion of cause and effect?

Re: This is reusable code

2008-06-18 15:30 • by AC (unregistered)
200983 in reply to 200777
nimis:

And you can't use the VERSION_CODE variable anywhere


True, as it's a macro.

Re: It Gets Worse Each Year

2008-06-18 15:43 • by gruckiii (unregistered)
200987 in reply to 200768
James R. Twine:

Capcha: dolor -- a dull color maybe?


That's what we call Canadian dollars eh.
« PrevPage 1 | Page 2Next »

Add Comment