From: "David A. Black" Date: 2007-08-24T20:09:28+09:00 Subject: Re: something I just found out, am sharing (:newbish) Hi -- On Fri, 24 Aug 2007, Robert Dober wrote: > On 8/24/07, Simon Schuster wrote: >> 075:0> a = "hello" >> "hello" >> 076:0> a += " there." >> "hello there." >> 077:0> >> >> >> neat! > not really :( > a += " there" is > a = a + " there" > > a << " there" > > I might be accused of premature optimizationism (A word I just made > up, I have to make an ECR ;). Don't worry -- there's no Academie Anglaise :-) > But seriously there is just no need to pay the cost of the > construction of another String / Array. > Performance difference is already enormous for moderately long strings : It depends, though; sometimes you might want a copy, sometimes you might definitely not. So the + vs. << decision may not be premature, and the right decision may not even be the optimizing one :-) David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)