Here is a proposal to allow number groupings in numeric literals.
It allows the optional introduction of a single character (here suggested as _) at any position separating consecutive digits shown in the following examples:
0x1200_0070 == 0x12000070
123_456 == 123456
10_000.40 == 10000.42
Problem being addressed:
- Reducing frequency of mistakes in numbers with repeated strings of similar digits
- Readability of numbers
Numeric constants with lots of repeated numbers happen especially with addresses and 64bit numbers.
Embedded platforms for instance have memory mapped addresses that I've caught myself making mistakes at entry.
Human languages have introduced typographic markings for number groupings: thin spaces, commas and dots.
Number groupings vary also between cultures, some mark the thousandth, some the ten-thousandth.
Programming languages of the C family: C++14 has introduced with the ' has an optional number grouping.
The character _ has been chosen in some documentations (I've seen it used in hardware manuals)
Increased readability, optional
- Implementation cost: small (lexer change only)
- Maintenance cost: small (does not interact with other language features)
- User cost: using the feature is optional, so users who don't like it can ignore it. One character is easy to learn and probably isn't too taxing even if it differs from other languages.
- Opportunity cost: the chosen character is can't be used anymore as a digit