Why D is not popular enough?

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 22 05:47:34 PDT 2016


On Sunday, 21 August 2016 at 16:31:41 UTC, Andrei Alexandrescu 
wrote:
> Consider:
>
> void fun(byte);
> void fun(int);
> fun(b + c);

Does anybody actually do that in the real world? Given the int 
promotion rule, such an overload is something i'd flag as always 
bug prone and confusing anyway.

With D's current rules, I am more likely to make just the int 
version and cast stuff down inside to get user code to compile 
more easily. My color.d, for example, has this:

         /// Construct a color with the given values. They should 
be in range 0
<= x <= 255, where 255 is maximum intensity and 0 is minimum 
intensity.
         nothrow pure @nogc
         this(int red, int green, int blue, int alpha = 255) {
                 // workaround dmd bug 10937
                 if(__ctfe)
                         this.components[0] = cast(ubyte) red;
                 else
                         this.r = cast(ubyte) red;
                 this.g = cast(ubyte) green;
                 this.b = cast(ubyte) blue;
                 this.a = cast(ubyte) alpha;
         }


Just because I got sick of constantly doing the casts on the user 
side. VRP is brilliant in little cases, but the fact that it 
doesn't work across statements really hurts it in real world use.

These casts are arguably wrong, defeating the point of the no 
implicit narrowing rule, but when a rule is so annoying that you 
hack around it, it has already failed.



More information about the Digitalmars-d mailing list