Implicit enum conversions are a stupid PITA

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Mar 25 12:20:43 PDT 2010


On 03/25/2010 01:45 PM, Walter Bright wrote:
> Andrei Alexandrescu wrote:
>> A: Use octal!"177"
>>
>> W: Ugh.
>>
>> A (esprit d'escalier): If you don't like the universal notation you
>> invented, who will?
>
>
> Good point. As I recall, we expended an enormous amount of effort
> working on template syntax, and I certainly feel that
>
> octal!"177"
>
> is far better than, say:
>
> octal<"177">.value
>
> but when I compare it to
>
> 0177
>
> that's just hard to beat. A customized syntax is always going to be
> better than a generic one. The octal syntax is used in several widely
> popular languages, and is convenient and looks attractive. It's used a
> lot in dealing with the unix file system.

Symbolic constants are the best way to deal with the filesystem.

It's not at all hard to beat. It would be if octal constants would be 
ubiquitous and ubiquitously useful. To disabuse yourself of that 
fallacious notion, PLEASE grep ALL your code for

[^0-9A-Za-Z."%_:\]0[0-9]

and let us know how many instances you find.

druntime has 152 octal constants for a total of 53130 lines. That's one 
for each 350 lines of code, or less than 0.3%. Ironically, most 
occurrences are used in defining symbolic constants that are good style 
for handling permission bits.

For Phobos I counted 11 true positives in 93,963 lines, which means one 
per 8542 lines of code or 0.01% of total.


Andrei



More information about the Digitalmars-d mailing list