From: "Aleksi Niemelä" Date: 2000-12-18T15:36:29+09:00 Subject: [ruby-talk:7549] Re: flatten_by(n) David, Ben discuss: > > >I'm using concat instead of '+=' because concat is a lot faster. > > >(Surprisingly faster, to me.) > > > > It it surprising to me that it is faster. IMO += should be just > > syntactic sugar... > > I also found it a little surprising -- in fact, at one point a while > ago, I tried to do "concat!" and then realized that concat was concat! > (if you see what I mean), while + was what I thought concat would be. To me idiom str += other looks slower than str.concat other. The reason is just the same as for Ben. += is just syntactic sugar. It makes the idiom to be actually str = str + other. And there we first take string str and call it's self-non-destructing method + passing other as a parameter. The resulting object, which is not str, is then assigned to str. So we're creating a new one. Whereas concat appends to the end, and does not create anything. Also the name of concat is descriptive enough (at least to me). So there's no need to have specificly concat!. - Aleksi