Octal literals have their uses (you Unix haters skip this one)

Allen Wirfs-Brock allen at wirfs-brock.com
Thu Jan 12 14:04:01 PST 2012

On Jan 12, 2012, at 12:57 PM, Brendan Eich wrote:

> No, let's not "do everything". That's a bad way to make standards.
> We should acknowledge that octal is used in JS today and it'll die hard in certain quarters. I don't think this was considered carefully when the decision to ban octal in strict mode was made.

My recollection (could be faulty) is that the decision was motivated by a desire to eliminate the error-proneness of the "leading 0 means octal" syntax accompanied by insufficient thought regarding modern use cases for octal. The Unix file permissions is a good one and of course anybody writing a PDP-8 simulator will appreciate the availability of octal

> If we want to support octal in strict mode, we can certainly ban crazy noctal (08, 09). If we choose to prefix, we should pick one prefix (and it should almost certainly be the same one in Python, Ruby, and CoffeeScript: 0o). Binary is plausible (0b), but after that I see no need for arbitrary-radix literals.

I think adding 0o to strict mode (while continuing to ban all leading 0digit octal constants (not just 08 and 09)) would be the best way to go.  The fix for lack of octal being a barrier to strict mode adoption is for implementor to quickly add 0o constants as an (allowed) extension to strict mode (do it today!).  Of course, there is nothing preventing implementations to from also supporting the same extension in non-strict JS code.

0644 not having in strict mode should only be a minor adoption barrier if 0o644 is available everywhere.


More information about the es-discuss mailing list