From: Markus Date: 2004-10-13T02:14:30+09:00 Subject: Re: Ruby Directions (was Re: quality of error messages) On Tue, 2004-10-12 at 09:36, Austin Ziegler wrote: > On Wed, 13 Oct 2004 01:28:23 +0900, Markus wrote: > > The odd thing is, all you are generally getting with them is a bit > > of syntactic sugar. Consider the relationship between: > > > > s = gsub(p,v) > > s.gsub!(p,v) > > > > i = i + k > > i += k > > > > Unless you have lent a friend a reference to s and are using it to send > > secret messages, you aren't really depending on the mutability of > > strings so much as the modifability of variables. > > The two aren't equivalent. In fact, the following holds true in Ruby: > > def gsub(search, replace) > self.dup.gsub!(search, replace) > end > > So String#gsub! isn't at all equivalent to i += k, because: > > s = t = "foo" > s.gsub!(/$/, "t") # => "foot" > puts t # => "foot" That's exactly what I meant by the phrase "Unless you have lent a friend a reference to s and are using it to send secret messages" -- t, in this case, being s's friend. My point was that: > s = t = "foo" isn't all that common. It's as likely when it does happen that the user (especially the nuby) is expecting it to behave like "s = (t = "foo").dup -- in other words, the whole reason they are assigning to both s and t is so that they will have "two copies" of the string. > I know that I use String#<< quite a bit, which means that nearly > everything that I do depends on the mutability of Strings. (Well, to > be more accurate, I use #<< quite a bit, and assume that it will Do > The Right Thing, which means that I depend on the mutability of > Strings). Sure. For that matter, I do as well. *smile* So are you wanting Integer to be mutable too? -- Markus (a.k.a. "the devils advocate")