From: Austin Ziegler Date: 2004-02-26T00:56:18+09:00 Subject: Re: Operators +, += and = in Ruby 2 On Thu, 26 Feb 2004 00:14:50 +0900, Robert Klemme wrote: > Operator += can't be user defined but instead is extended to a > combination of "+" and assignment: "x += y" becomes implicitely "x = x + > y". > 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" > The reason I'm offering this is performance: "x = x + y" is slower than > an inplace manipulation (that += would do), which is often what's desired > here. Better to have a new method for this: x.add(y) The problem is that assignment works on variables, but + is a method call on an object. Ruby is the only language that I know that has such a distinction, but it's one that (to me) makes perfect sense. -austin -- austin ziegler * austin@halostatue.ca * Toronto, ON, Canada software designer * pragmatic programmer * 2004.02.25 * 10.55.34