On Oct 23, 10 11:11, bearophile wrote:
This is a minor thing, if you aren't interested, ignore it.

The support for underscore in number literals as done in D and Ada is a feature 
I like a lot. But you may write:

long x = 1_000_000_000_00;

The usage of underscores there doesn't correspond to the thousands, this may 
lead to mistakes, and then maybe to bugs. Something similar may happen for hex 
(both integral and FP), octal or binary number literals (that usually you don't 
divide in groups of 3).

In D I have written numbers with underscores positioned in a way that I 
consider wrong.

So isn't it better to restrict the usage of the underscores every 3 digits 
(starting from the less significant one) for decimal literals, and every 4 or 8 
or 16 or 32 digits in binary/octal/hex number literals? (4 or 8 or 16 or 32 
means that you are free to use one of those four styles, but then you need to 
use it consistently in one number literal).

A problem with this is that not everybody uses groups of 3 digits in decimal 
number literals (Do Chinese people use groups of four?).

(When I have proposed to introduce underscores in Python number literals they 
have discussed about this sub topic too.)

Bye,
bearophile

Not all kinds of numbers are naturally grouped by 3 digits, e.g. phone number 555_6789, credit card numbers 1234_5678_9012_3456L etc. (arguably they may be better stored at strings though.)

std/traits.d of Phobos also contains non-standard position of separation:

enum ParameterStorageClass : uint
{
    /**
* These flags can be bitwise OR-ed together to represent complex storage
     * class.
     */
    NONE    = 0,
    SCOPE   = 0b000_1,  /// ditto
    OUT     = 0b001_0,  /// ditto
    REF     = 0b010_0,  /// ditto
    LAZY    = 0b100_0,  /// ditto
}

Reply via email to