[Issue 1596] op*Assign should return void

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jul 5 08:43:47 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=1596


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug at yahoo.com.au


--- Comment #6 from Don <clugdbug at yahoo.com.au> 2011-07-05 08:38:38 PDT ---
(In reply to comment #5)
> D should not be forcing behavior on normal functions, which operators are. 
> They are special in that if defined in a specific way, they will be used when
> using operators, but other than that, they are ordinary functions.  If you want
> to force behavior, make the operators keywords (like C++).  Otherwise, you have
> special rules for ordinary symbols.  Lowering is supposed to work by simply
> rewriting code, not by requiring certain signatures.

??? 
The existing language doesn't obey these rules, which you've apparently just
made up.

> This relates to Andrei's later bug regarding opEquals - the compiler currently
> requires a certain signature for opEquals, and it simply gets in the way of
> writing efficient or usable code.

Actually the problem with opEquals is that there is NO option which works
properly. Giving you more bad options wouldn't help.

> Besides, I think Andrei's original point is that it was impossible to do the
> most efficient thing (return the lvalue of this), which is no longer the case.
> So this was an attempt to solve that problem using a language rule instead of
> adding ref returns.

No. The point is this: There is only ONE correct choice for the return value:
it must be some form of 'return this'. The compiler is better equipped to work
out the most efficient way to do it, than the programmer is.

Giving freedom to choose the return value does only two things: 
(1) it gives you an opportunity to make a mistake. 
(2) it adds extra noise in the code.

The one legitimate use of a return value is in expression templates, but as
already mentioned, they don't work with opCmp.

-- 
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