Uniform Function Call Syntax?
Era Scarecrow via Digitalmars-d
digitalmars-d at puremagic.com
Thu Mar 3 18:09:25 PST 2016
On Friday, 4 March 2016 at 01:56:34 UTC, user001 wrote:
> Was just wondering why UFCS only works in one direction, that
> is why functions can be used as if it were part of a
> struct/class but not the other way around.
>
> int dot;
>
> float value = dot(a, b); // would be same as a.dot(b)
> // doesn't try to use local "int dot"
Immediately looking at only that part of the code, i have to ask
'how the hell are you calling the int???'. Of course i can tell
from your source dot is also a function in the vector.
Considering dot could now shadow the variables or function
names, it would quickly QUICKLY become annoying. A hierarchy of
how the call is used plus the documentation of what it's
obviously doing is a much better approach. Not to mention we've
been using . and -> and * so long for accessing/de-referencing
members that are attached so long that changing it is probably
not an option. MAYBE if you were starting a language from
scratch, but in this case i would firmly say no, this is ugly and
confusing.
More information about the Digitalmars-d
mailing list