Implicit enum conversions are a stupid PITA

bearophile bearophileHUGS at lycos.com
Thu Mar 25 17:47:39 PDT 2010


Walter Bright:

>Yes, we can endlessly rename keywords, but in the end, what does that accomplish that would compensate for upending every D program in existence?<

I can list few pro/cons, but then the decision is not mine.
I'll close my "bug" report on the base of the answers, because this is only one of the about 15 little breaking changes I have proposed (the disallowing of the octals syntax was another one of them, but after your last answer I consider it a closed problem, the http://d.puremagic.com/issues/show_bug.cgi?id=2656  can be closed).

The type names in D have a nice symmetry, and they are not ex-novo, they are diffused in other languages. I have appreciated them.

I think of a "byte" as unsigned value. This has produced a small bug in a D program of mine. I think changing the names of the signed/unsigned values can solve this.

In C# the type names have the same symmetry as in D, with u for the unsigned ones, but later I have found that it seems C# devs agree with me in thinking of bytes as unsigned, because they break the symmetry using:

The signed/unsigned bytes in C# are:
- The sbyte type represents signed 8-bit integers with values between -128 and
127.
- The byte type represents unsigned 8-bit integers with values between 0 and
255.

C# is usually a carefully designed language, much better designed than C++, so its example is not negligible. Yet, I don't fully like the C# solution, because even if I think of bytes as signed, all the other C#/D types that don't start with "u" are signed (well, chars too are an exception). So C#/D newbies can follow the symmetry and write wrong code again.

So I have suggested ot keep the "ubyte", deprecate the "byte", and introduce a "sbyte" (signed byte). Now it's easy to tell apart what's the signed and what's the unsigned. "byte" can later be removed.

-----------------

The wchar/dchar are short names, easy to write, but for me and a person I've shown/taught D it doesn't result easy to remember their size in bytes. "w" stands for wide, "d" for double, this is easy to remember. But how wide is wide? That's why I have suggested to adopt more descriptive names for them.

A way to invent descriptive names is to use names similar to the byte/shot/int/long integers. Or to use numbers after the "char". I guess now it can be too much late to change type names...

Bye,
bearophile



More information about the Digitalmars-d mailing list