"Dennis Ranke" <dennis.ranke / epost.de> schrieb im Newsbeitrag
news:opr3y1zulz4wwk8i / News.CIS.DFN.DE...
> On Wed, 25 Feb 2004 16:12:16 +0100, Robert Klemme <bob.news / gmx.net>
wrote:
>
> > Now, wouldn't it be better to turn that around and have people define
> > operator += and automatically convert operator + like in:
> >
> > "x + y" becomes implicitely "x.dup += y"
> >
> > [...]
> >
> > What do others think?  Did I overlook something?
>
> Yes, I think so. With your proposed change it would be impossible to
> express operations where the result has a different type than the first
> operand, like, for example:
>
> Float = Vector * Vector   # (dot product)
> or
> Vector = Matrix * Vector

I didn't overlook that one.  It was in the first post already:

<quote>
On the downside:
[...]
 - dup might or might not be the appropriate method to create a copy
depending on the class at hand. When defining operator +, we are currently
free in deciding what's the type of result of this operation.  That
freedom would definitely go away.
</quote>

A solution would be to provide another method (maybe #copy or #op_dup or
similar) that defaults to #dup but can be overridden to get another return
value.

> Of course, it would be possible to automatically define a missing +=
> using a defined +, and a missing + using a defined +=. Whether this
would
> be a good idea is certainly debatable.

That would lead into the directon of C++ where you can overload all these
operators independently.  Dunno whether that is a good idea or not, but I
always liked the idea that there was only one set of operators I needed to
define and got the rest for free.  We could maintain this by defining #+,
#- etc. in Object using #+= etc. internally.  So we would retain the
automatism while not reducing freedom too much.

Any other thoughts on this?

Kind regards

    robert