Less free underscores in number literals

bearophile bearophileHUGS at lycos.com
Fri Oct 22 20:11:42 PDT 2010


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


More information about the Digitalmars-d mailing list