Skip to main content
added 20 characters in body
Source Link
kaya3
  • 20.8k
  • 46
  • 126

The other answers so far have exclusively focused on advantages. There are two disadvantages I can think of, though neither is really a strong enough reason to exclude this feature from a language.

The first disadvantage is particular to the C-style syntax for octal numbers, that is that integer literals beginning with a 0 are treated as octal (base 8). So for example, 012 is not equal to 12. This can be confusing and lead to mistakes; there are some real-world contexts in which it is normal to write decimal numbers with leading zeroes, particularly where this allows numbers to have a fixed number of digits and be sorted lexicographically.

The second disadvantage is that it adds a complication to the standard library's functions for parsing strings as numbers. Particularly, if there is more than one syntax for a number literal in the language, then the user also needs to think about whether or not those different syntaxes are handled by the parse function. In the worst case, the parse function handles other syntaxes and the user may not even be aware that those other syntaxes exist, causing incorrect results when the input string happens to match one of the other syntaxes.

An example is Javascript'sthe parseInt function in older versions of Javascript, where parseInt('08') iswas equal to 0, not 8, because this string is in octal notation ─ but the string is likely to come from an end-user who has no idea what octal is, and who thinks 08 is a perfectly sensible way of writing the number 8. Empirically, this has tripped up quite a few people, based on the number of votes and duplicates of this Stack Overflow question.

The other answers so far have exclusively focused on advantages. There are two disadvantages I can think of, though neither is really a strong enough reason to exclude this feature from a language.

The first disadvantage is particular to the C-style syntax for octal numbers, that is that integer literals beginning with a 0 are treated as octal (base 8). So for example, 012 is not equal to 12. This can be confusing and lead to mistakes; there are some real-world contexts in which it is normal to write decimal numbers with leading zeroes, particularly where this allows numbers to have a fixed number of digits and be sorted lexicographically.

The second disadvantage is that it adds a complication to the standard library's functions for parsing strings as numbers. Particularly, if there is more than one syntax for a number literal in the language, then the user also needs to think about whether or not those different syntaxes are handled by the parse function. In the worst case, the parse function handles other syntaxes and the user may not even be aware that those other syntaxes exist, causing incorrect results when the input string happens to match one of the other syntaxes.

An example is Javascript's parseInt function, where parseInt('08') is equal to 0, not 8, because this string is in octal notation ─ but the string is likely to come from an end-user who has no idea what octal is, and who thinks 08 is a perfectly sensible way of writing the number 8. Empirically, this has tripped up quite a few people, based on the number of votes and duplicates of this Stack Overflow question.

The other answers so far have exclusively focused on advantages. There are two disadvantages I can think of, though neither is really a strong enough reason to exclude this feature from a language.

The first disadvantage is particular to the C-style syntax for octal numbers, that is that integer literals beginning with a 0 are treated as octal (base 8). So for example, 012 is not equal to 12. This can be confusing and lead to mistakes; there are some real-world contexts in which it is normal to write decimal numbers with leading zeroes, particularly where this allows numbers to have a fixed number of digits and be sorted lexicographically.

The second disadvantage is that it adds a complication to the standard library's functions for parsing strings as numbers. Particularly, if there is more than one syntax for a number literal in the language, then the user also needs to think about whether or not those different syntaxes are handled by the parse function. In the worst case, the parse function handles other syntaxes and the user may not even be aware that those other syntaxes exist, causing incorrect results when the input string happens to match one of the other syntaxes.

An example is the parseInt function in older versions of Javascript, where parseInt('08') was equal to 0, not 8, because this string is in octal notation ─ but the string is likely to come from an end-user who has no idea what octal is, and who thinks 08 is a perfectly sensible way of writing the number 8. Empirically, this tripped up quite a few people, based on the number of votes and duplicates of this Stack Overflow question.

Source Link
kaya3
  • 20.8k
  • 46
  • 126

The other answers so far have exclusively focused on advantages. There are two disadvantages I can think of, though neither is really a strong enough reason to exclude this feature from a language.

The first disadvantage is particular to the C-style syntax for octal numbers, that is that integer literals beginning with a 0 are treated as octal (base 8). So for example, 012 is not equal to 12. This can be confusing and lead to mistakes; there are some real-world contexts in which it is normal to write decimal numbers with leading zeroes, particularly where this allows numbers to have a fixed number of digits and be sorted lexicographically.

The second disadvantage is that it adds a complication to the standard library's functions for parsing strings as numbers. Particularly, if there is more than one syntax for a number literal in the language, then the user also needs to think about whether or not those different syntaxes are handled by the parse function. In the worst case, the parse function handles other syntaxes and the user may not even be aware that those other syntaxes exist, causing incorrect results when the input string happens to match one of the other syntaxes.

An example is Javascript's parseInt function, where parseInt('08') is equal to 0, not 8, because this string is in octal notation ─ but the string is likely to come from an end-user who has no idea what octal is, and who thinks 08 is a perfectly sensible way of writing the number 8. Empirically, this has tripped up quite a few people, based on the number of votes and duplicates of this Stack Overflow question.