LWN.net Logo

What If I Don't Actually Like My Users?

What If I Don't Actually Like My Users?

Posted Apr 5, 2008 15:09 UTC (Sat) by Wummel (subscriber, #7591)
Parent article: What If I Don't Actually Like My Users?

The Javascript parseint() interface comes to my mind. Usually, it parses strings to integers with a decimal base. But it silently switches to octal when the string has leading zeros: parseInt('08') equals zero!

So, you pretty much always have to specify the base as second argument, which is annoying: parseInt('08', 10) gives the expected 8.


(Log in to post comments)

parseInt feature

Posted Apr 5, 2008 16:45 UTC (Sat) by ccyoung (subscriber, #16340) [Link]

thanks for that reminder - nothing like getting bit in the butt

What If I Don't Actually Like My Users?

Posted Apr 7, 2008 8:28 UTC (Mon) by Los__D (subscriber, #15263) [Link]

What's wrong with the 0 prefix giving octal? It does exactly the same in C, just as both C and
parseInt() treats 0x as hexadecimal.

Anyway, ActionScript v3 has dumped this, probably meaning it's also gone from ECMAScript, so I
guess JavaScript will pick up the changes sooner or later.

They kept the '0x' prefix for Hexadecimal though, which seems a bit strange to me, either keep
them both, or dump them both. Oh well, maybe it's just because noone really uses octal in
ECMAScript and derived scripts.

What If I Don't Actually Like My Users?

Posted Apr 7, 2008 11:09 UTC (Mon) by dvdeug (subscriber, #10998) [Link]

What's wrong with the leading 0 making it octal is that if you have to deal with people who
aren't mathematicians or computer scientists, they probably won't know what octal is. If they
add a leading zero by accident, odds are they'll not be able to figure out what they did wrong
or why the results came out the way they did, and unless you're lucky enough to be standing
over their shoulder while they do it, their bug reports won't have enough information to
replicate it. The difference, to them, between typing in 0507 and 507 is nothing. Hence using
parseInt with a UI is going to cause rare, hard-to-trace problems in exchange for a feature
that no one cares about. (Really, even among computer geeks, few people use octal.)

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds