From: Gavin Sinclair Date: 2003-02-19T13:45:42+09:00 Subject: Re: String#+ operatorbroken? On Wednesday, February 19, 2003, 3:25:49 PM, Jason wrote: >> >> Remember, s += "whatever" is a syntax sugar for >> >> s = s + "whatever" >> >> so that it allocates new string object every time, whereas >> >> s << "whatever" >> >> appends "whatever" to existing string object. >> >> matz. >> > Hmm. Would it make sense to 'special-case' that? They accomplish the > same thing logically (right?), and I would expect a language to > evolve out these hidden 'performance-bombs'. In fact, anytime > there's an operator= method, maybe it should never allocate a new > object? This was discussed fairly extensively on -talk not so long ago. Check the archives of the last few months. Basically, programmers have to take some responsibility for the methods they use. It's something of a Ruby idiom to use << for appending, and if you want to program in Ruby, you need to learn some Ruby idioms. Also consider the fact that the "+" method can be redefined. Gavin