Why don't underscores in numbers enforce proper formatting?

simendsjo simendsjo at gmail.com
Wed Mar 6 13:21:42 PST 2013


On Wednesday, 6 March 2013 at 21:15:07 UTC, simendsjo wrote:
> On Wednesday, 6 March 2013 at 21:06:43 UTC, ixid wrote:
>> The underscores in values such as 1_000_000 aid readability 
>> but DMD doesn't see anything wrong with any placement of 
>> underscores as long as they follow a number. Is there any 
>> reason to allow uses like 1_00_000, which are typos or 
>> exceedingly lazy modifications of value, and not enforce 
>> digits to form sets of three after the first underscore?
>
> If someone uses different semantics on their numbers (like 
> ISBN), having underscores in different places will help 
> readability as the underscores can show the semantics of the 
> number.

Norwegian SSNs have this structure for instance: ddmmyyxxxcc 
where ddmmyy is day/month/year of birth, xxx is an auto increment 
number (that also shows somewhat the year of birth) and cc is 
control digits created from xxx where the last digit also 
indicates gender. This can be grouped in different ways: 
ddmmyy_xxx_cc, ddmmyy_xxx_c_c etc. based on what you find the 
most readable. Forcing this to be d_dmmy_yxx_xcc will clearly be 
suboptimal. Of course, hardcoded SSNs in code is a bad example :)


More information about the Digitalmars-d-learn mailing list