From: William Djaja Tjokroaminata Date: 2002-10-24T22:42:59+09:00 Subject: Re: Things That Newcomers to Ruby Should Know (10/16/02) dblack@candle.superlink.net wrote: > I don't think "a += 'str'" (or whatever) is creating an intermediate > object though, at least not in the sense that I understand the term. > It's just performing an assignment, not doing anything extra. Hi David, Probably "intermediate" is not an exact terminology; maybe "new" object is a better one? This can be shown by a = 'str' puts a.id # -> some number a << 'str' puts a.id # -> number unchanged (in-place modification) a += 'str' puts a.id # -> number changed (a new object is created) I think people with C++ background are used to the concept or convention that '+=' means in-place modification while '= self + something' means a new object creation. I think that is how we usually control performance in C++: we prefer to use '+=' unless the use of '=' is necessary. The aliasing/side-effects to other variables is of no concern because usually the '=' operator is overloaded (but then if someone forgets to overload the '=' operator then it may create a bug... :) ) Regards, Bill