feature req: extend property syntax func calls to classes, interfaces, primitives? also, final interface methods w. code

Oskar Linde oskar.lindeREM at OVEgmail.com
Tue May 22 08:17:02 PDT 2007


Henning Hasemann skrev:
> On Mon, 21 May 2007 22:54:43 -0700
> "David B. Held" <dheld at codelogicconsulting.com> wrote:
> 
>> Downs wrote:
>>> [...]
>>> 1) to extend the property syntax to classes and interfaces, _maybe_ even 
>>> arrays and primitive types.
>>> Such a change would allow one to write "interface barf { } void 
>>> test(barf b) { do stuff; } myBarf.test; "
>> This is related to a proposal to allow both member and free function 
>> call syntax.  That is:
>>
>> a.foo();
>>
>> could also be called as:
>>
>> foo(a);
> 
> Maybe the Dylan language (http://www.opendylan.org) would be of interest here,
> where actually no such thing such class methods exists
> but only global multi-dispatched methods with the syntactic
> sugar described above.

I agree. D (as well as C++, and to a lesser extent Java and many other 
languages) fails horribly at providing simple and consistent rules for 
polymorphism. Instead, we have several different kinds of polymorphism, 
each with special and somewhat incompatible rules.

There are at least four forms of polymorphism in D:
1) function/method argument overloading,
2) virtual method dispatch,
3) template function specialization (not yet polymorphic in DMD),
4) op_r- / op-overloading,

and combinations of the above -- all with slightly different rules and 
behaviors. At least, D doesn't have the C++ "polymorphism by #include 
files". :)

Techniques such as for example double dispatch is necessary only because 
the language isn't expressive enough. An illustration:

Given: A a; B b;

a.func();  // Run time polymorphism on a
func(b);   // Compile time polymorphism on b
a.func(b); // Run time polymorphism on a and compile time on b

There is no (good) reason a language shouldn't allow run time dispatch 
on for example both a and b for a.func(b) and func(a,b).

IMHO, Dylan does it right. Remove member functions/methods altogether 
and unify all forms of polymorphism. I have no illusions about this ever 
happening in D though. ;)

/Oskar



More information about the Digitalmars-d mailing list