From: dblack@... Date: 2002-10-24T20:21:54+09:00 Subject: Re: Things That Newcomers to Ruby Should Know (10/16/02) Hi -- On Thu, 24 Oct 2002, William Djaja Tjokroaminata wrote: > If a person has a C++ background, then probably the concept of creation of > intermediate object is troubling, because one of the many advices in C++ > books is something like: > > "When you pass an argument to a function, in general it is better to > pass it by reference instead of pass by value, because pass by value can > be much more expensive as it may involve the creation of an intermediate > object, while pass by reference will not." (To avoid modifying the > original object then the "const" type specifier is used.) > > Therefore, a person with a C++ background, who is used to avoiding the > creation of unnecessary intermediate objects, will be surprised that Ruby > does it *all the time* in its '+=' operator. (Furthermore, the creation > of equivalent intermediate objects may even be more "expensive" in Ruby > than in C++ in absolute terms.) 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. > Therefore, this type of question is, in my opinion, usually not originated > by practicality concern as much as caused by the differences in "school of > thoughts" in the programming world. C++ is more about > (computer's) performance, while Ruby is more about (programmer's) fun. :) I won't argue with that :-) though it's important to remember that there's nothing secret or subterranean about += in Ruby. It's just a way of performing an assignment -- so if that isn't what one wants (for performance or other reasons), one has all the information necessary to decide not to use it. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav