Perlessence

Code Blind Spots

January 19, 2008 09:53

I found this nugget on Slashdot in my morning RSS reading. Blizzard evidently uses a signed int to store the amount of money your character has. A player discovered this and posted a screenshot of the error message. So the question is: why did the Blizzard programmers think to trap and handle this error, but it didn't occur to them to make the gold field an UNsigned int?

Every coder I know has had moments like this, where we realize that we've coded defensively for every possible outcome except for one glaringly obvious situation. For example, a couple months ago at Gaia we ran out of user IDs because we used a signed medium int. No one ever thought that we'd have more than 8 million users. But given that user IDs are always positive, was there any reason to use a signed int? My particular weakness is race conditions: I'm not good at telling when one can occur or how to solve it. In the end, it's something to fix and laugh about, as long as it doesn't cause too much financial ruin!

© Probably a million other people from whom I've subconsciously stolen this layout. Also, Karen Ziv (me). Don't steal my stuff.