2 ms·
Underscores inside numbers! I had no idea. Yes, it's a very good idea. I bet someone out there hates it though. It's in Python, Javascript, and Java at leas
by buescher 5y ago
Underscores inside numbers! I had no idea. Yes, it's a very good idea. I bet someone out there hates it though. It's in Python, Javascript, and Java at least now... what others?
- pjmlp 5y agoYou missed C# and C++.
- adrian_b 5y agoWhile C++ 2014 added a digit separator, in my opinion using a single quote instead of an underscore as in Ada and in all the other languages following Ada was an extremely stupid decision. The rationale for this surprising choice was that a number starting with an underscore could be interpreted as an identifier. ??!! Why would anyone want to start a number with an underscore? Underscores are needed only inside long numbers. The syntax should have allowed underscores only inside numbers and there would have been no problems with backward compatibility, as such numbers would have been illegal before. The single quote cannot have been easier for parsing as the new use must not be confused by the parser with character literals, which can appear in the same context. The underscore was first introduced in a programming language by IBM PL/I (in 1964, when it was still named NPL) with the precise purpose of improving the readability of identifiers. Ada has extended this use to also improve the readability of long numbers. Why C++ has chosen a different character, which is normally used for completely different purposes, without having any decent justification for such a baffling decision, I cannot understand.