If I had my way
Jonathan M Davis
jmdavisProg at gmx.com
Mon Dec 12 20:25:33 PST 2011
On Tuesday, December 13, 2011 05:13:29 F i L wrote:
> On Monday, 12 December 2011 at 21:57:36 UTC, Jonathan M Davis
>
> wrote:
> > There has been discussion of UFCS (universal function call
> > syntax), which would then expand that beyond arrays to _all_
> > types - int, float, any user-
> > defined type, etc. However, there are a number of issues with
> > that (particularly with user-defined types; e.g. what if a
> > member function and a free function have the same name?), and
> > it has yet to be implemented. It may never be implemented.
>
> C# easily avoids member confusion with pseudo methods by using
> the 'this' keyword as a parameter attribute in the pseudo method
> (http://msdn.microsoft.com/en-us/library/bb383977.aspx). Any
> function(this a, b) can be invoked as: a.function(b) in C#. I
> understand using the 'this' keyword as a parameter attribute
> already serves a different purpose in D, but I'm sure another
> keyword ('pseudo' perhaps?) or equivalent syntax could be
> reached. At which point, any external pseudo method conflicting
> with an objects internal members could simply result in a
> compiler error (or, member functions could take priority over
> pseudo methods).
There have been a variety of suggestions on how to do it - including one
similar to what you're suggesting with the this keyword. However, it still
leaves the problem of disambiguation that I mentioned. What happens when
there's a free function and a member function with the same name and same
parameters? Which one gets called? It's issues like that which are more of a
problem than the exact syntax for declaring it IMHO. And all of those details
need to be sorted out in a satisfactory manner before we can add UFCS to the
language in any form.
For arrays, all you need to do is have the first argument be an array, and that
works great for arrays, but arrays don't have much in the way of functions
built in, so there's no conflict.
Realistically, at this point, I'd expect that if UFCS gets added any time
soon, it's going to require that someone other than Walter do it and that they
have do it very solidly, otherwise it could be a long time before it stands
any chance of happening, simply because Walter is focused on fixing major bugs
and stabilizing the compiler and isn't likely to look at adding new features
anytime soon if there's no dire need (even if they're backwards compatible).
- Jonathan M Davis
More information about the Digitalmars-d
mailing list