Does D have too many features?

F i L witte2008 at gmail.com
Sat Apr 28 16:37:13 PDT 2012


Peter Alexander wrote:
>> - opDispatch
>>   This is useful and of significant value if used the right 
>> way.
>
> Can you give me an example of it being used the right way?

It can be very useful for jQuery/JSON style dynamic objects:

     import std.variant, std.stdio;

     struct Dynamic {
         Variant[string] vars;

         void opDispatch(string key)() @property {
             return vars[key];
         }

         void opDispatch(string key, T)(T value) @property {
             vars[key] = value;
         }
     }

     void main() {
         auto foo = Dynamic();

         foo.a = "A";
         foo.b = 11;

         writefln("%s, %s", foo.a, foo.b);
     }


>>   I hope you are not actually serious about that '->' part.
>
> I'm serious. I don't like overloaded syntax.  foo.bar shouldn't 
> also mean (*foo).bar -- it causes confusion and introduces 
> ambiguities when either could work. Combine this with 
> opDispatch, UFCS and function overloading and your in for some 
> nasty headaches.

Craziness. What could you possibly gain is there in forcing a 
pointer distinction at every point that it's used? We already 
declared the variable as a pointer, we don't need to be reminded 
of that fact at every line.


More information about the Digitalmars-d mailing list