From: Austin Ziegler Date: 2002-10-24T04:24:37+09:00 Subject: Re: Things That Newcomers to Ruby Should Know (10/16/02) On Thu, 24 Oct 2002 04:05:44 +0900, Mills Thomas (app1tam) wrote: > It's not non-sensical. If it appeared that I mean for all objects > to use append(), then I was not clear. Using append() was just an > example. With numbers it might mean add_on(). With Strings it > might mean Concat(). With Animals it might mean graft(). With > TrainCars, it might mean hitch(). > > The point is, an object can have another object added to it. The > fact that we do it easily with RealNumbers is only a cultural > truism. It is not a stretch to think of graft() with an Animal. > And so it is sensical. :-) (for non-english speakers, it is > understandable). It still remains non-sensical because it then becomes necessary to create language exceptions for each type -- and each new type. With Ruby's current behaviour, one only has to: def +(other) end To get both + and += operators. As someone else pointed out, C++ defines + and += separately so that one or the other can be valid, and they can do completely opposite things, at that. IMO, C++'s model is the one that's nonsensical. (While the original C implementation of += may not be = +, it acts like it.) I think part of the problem in understanding why it's non-sensical is that all variables in Ruby are references to objects. As others pointed out: a = "foo" b = a b += "bar" p [a, b] Under your model, then both variables would have the value "foobar". Under Ruby's existing model, b no longer aliases a, but a new string. Ultimately, I think that any language that allows the definition of += separately from + is broken because it allows really dumb, really broken things in exchange for a minor performance quibble. If you explicitly want performance benefits in string concatenation, use String#<< -- it's what I do. If I can't afford to take the chance of modifying the original value, then I use +=. -austin -- Austin Ziegler, austin@halostatue.ca on 2002.10.23 at 15.14.29