Is the world coming to an end?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Apr 3 09:14:09 PDT 2011


On 4/3/11 2:14 AM, Russel Winder wrote:
> On Sat, 2011-04-02 at 18:20 -0500, Andrei Alexandrescu wrote:
>> On 4/2/11 5:27 PM, ulrik.mikaelsson at gmail.com wrote:
>>> A D-newbie would probably be able to guess 0o for octal, but
>>> hardly octal!. octal! breaks the rule of least surprise.
>>
>> I fail to infer how using the word "octal" for an octal literal is
>> surprising at all.
>
> The problem is not that it is a poor solution in isolation, it is
> the conflict between 0b... and 0x.. versus octal!...  Why is octal
> being discriminated against compared to binary and hexadecimal?

It's very simple. You are making a number of fallacious assumptions
which logically lead to a wrong conclusion.

First fallacy is:

> What is the use for binary literals or hexadecimal literals, I can't
> think of one.

Just looking through std/ yields 1849 lines with 0x in them, of which 
many have several instances on the same line.

The second fallacy is assigning equal weight to every feature or 
potential feature. A language should not be a democracy.

The third fallacy is a unidimensional view of consistency. It's very 
easy to first limit the notion of consistency to only one possible 
dimension, to then show that a lot of stuff is inconsistent. In reality 
there are many dimensions of consistency, and choosing their right 
relative importance is much of the difficulty of language design.

Keeping 0x in the language is consistent with the general similarity of 
D with C, C++, Java, and many others.

Eliminating 0777 from the language is consistent with the notion that 
leading zeros are insignificant in regular decimal notation in math. It 
is also consistent with the desire of preventing subtle mistakes made by 
people who make the math-based assumption.

Adding octal!777 to std.conv is consistent with the notion that there 
still are a few uses for octal constants that are worth a presence in 
the standard library. It is also consistent with the desire to foster 
other user-defined literals defined from the same mold.


Andrei


More information about the Digitalmars-d mailing list