Does D have too many features?
Jonathan M Davis
jmdavisProg at gmx.com
Sat Apr 28 17:31:37 PDT 2012
On Sunday, April 29, 2012 01:54:35 Peter Alexander wrote:
> On Saturday, 28 April 2012 at 23:37:14 UTC, F i L wrote:
> > Peter Alexander wrote:
> >> 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.
>
> It matters when you have things that imitate pointers (e.g. smart
> pointers). Those will have their own members, separate from the
> pointee's members, so ptr.foo could refer to the smart pointer's
> members or the pointee's members.
For better or worse, the solution for smart pointers in D would be to use
opDispatch, but it _does_ still mean that the type pointed to can't have any
of the same functions as the smart pointer (or at least, they would have to be
called differently, since . would use opDispatch and therefore use the smart
pointer's function), so you _do_ lose something over the -> syntax here.
However, the overall gain is usability probably still outweighs that. I
wouldn't exactly have been heartbroken if -> had been in D, but simplicity of
not needing it can be very nice - and it can be invaluable in the case of
templates, because then you don't have to distinguish between structs,
pointers to structs, and classes when calling functions on them.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list