[Issue 9786] Allow [non-member|UFCS] implementation of operators
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Mar 30 09:57:04 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9786
--- Comment #7 from Maxim Fomin <maxim at maxim-fomin.ru> 2013-03-30 09:57:00 PDT ---
(In reply to comment #6)
> (In reply to comment #5)
> > Operator overloaded methods are special functions.
>
> No, they are specially named normal functions with some syntax sugar support.
> They can just as well be called as normal functions/methods. In this case, UFCS
> already works.
This is exactly why they are special - because some language constructs are
transformed to them (they have "some syntax sugar support"). Other methods do
not have such feature. Besides, UFCS allows simply to transform function call
to method call, it does not promise to support "some syntax sugar" of some
"specially named normal functions" beyond its scope.
>
> > There are several problems with UFCSising them.
> > ...
>
> There are no issues not common to other functions. Operator overloading is all
> about syntax. It is completely pointless to single out the operator overloading
> functions in any other way.
>
Nobody tries to single out them. They are already singled outed by the fact of
their existence.
> The objections are simply invalid:
>
> 1) (template) functions can always be renamed, even if they happen to be named
> eg. opBinary.
.. in general case when you have ordinal method. Renaming foo() to myFoo() is
not a big deal. Renaming a[i[$]] = b[] in terms of explicit opSlices and
opIndexes is not that fruitful. What's more, in case of foo() => myFoo() UFCS
is still useful, while in case of a[i[$]] = b[] => opSlice etc. you cannot
write nice expressions (no way for +mybin operator), so supporting this feature
loses sense. In short, making UFCS to support "some syntax sugar" beyond its
purpose is a feature which can be easily abused and broken, so why should it be
supported?
>
> 2) Druntime will _never_ catch up UFCS (template) functions anyway. It does not
> matter if they are called eg. opUnary or toString.
>
> BTW, I do not think this is an enhancement. According to the online docs and
> TDPL, it should work.
This was not supposed to work. UFCS was made to perform simple method
transforms. Transforming expressions info function calls is separate issue.
Some programmers demand this feature because they considered it as a "cool" due
to "some syntax sugar support". The problem is that some others also think so
and start to overload. And since the amount of just "specially named normal
functions" is fixed and limited, probability to run into conflict with
opWhatever is higher than in case of ordinal method. Nicest case happens when
they overload operator methods simultaneously in independent modules and
somebody decided to use each of the modules.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list