Octal escape sequences in string and regexp literals
caitpotter88 at gmail.com
Fri Jan 2 13:08:11 PST 2015
I think there are a few reasons why you wouldn't want these.
First and foremost, octal escapes (\nnn) are just an alternative
equivalent to hex escapes (\xnn). Most software developers spend a lot
more time dealing with hex when it comes to byte values, and very
little time with octal literals outside of things like unix file
permissions. The most useful octal literal would be \0, and this is
already explicitly permitted in strict mode. So, I don't think there's
any real compelling use case for the alternative representation of
byte values. So to summarize, supporting these in strict mode would be
adding another way to accomplish the same given task (which grows the
language for no real reason and with no benefit), does not make string
literals easier to read and understand, and does not enable software
developers to perform any compelling task which was not more easily
accomplished using hex literals. Finally, the most common use-case for
this feature is already supported in strict mode.
More important, octal escape sequences are a bit liberal, in that they
can be of several lengths, with a pretty wide range of delimiters.
This, I think, results in many cases where octal escape sequences are
used by accident, rather than intentionally. It's a footgun, and
ideally that footgun should not be there.
I feel like the "refactoring pain" argument is not very compelling,
because I am not convinced beginners are likely to use octal literals
on purpose (or even by accident).
More information about the es-discuss