From: Robert Klemme Date: 2004-10-12T16:09:37+09:00 Subject: Re: Ruby Directions (was Re: quality of error messages) "Gavin Sinclair" schrieb im Newsbeitrag news:156643468789.20041012121518@soyabean.com.au... > On Tuesday, October 12, 2004, 11:32:31 AM, David wrote: > > > With all the recent talk about ranges (much, but not all, of which > > I've read), I've been trying to put my finger on why I find the idea > > of a mutable Range sort of paradoxical. I'm far from having any kind > > of sound theoretical grounding or rationale... but anyway: > > > I think of a range as kind of a fact. For example: (0..10) is "the > > fact of being between 0 and 10, inclusive". In which case, changing > > *that fact* -- e.g., having "the fact of being between 0 and 10" > > *itself* become "the fact of being between 6 and 12" -- makes no > > sense. I guess I think of ranges almost more like numbers; it would > > make sense to me if (0..10) were literally the same object everywhere > > it appeared. > > I agree, David, FWIW, but one doesn't even need to go that far in > justifying immutability. Many things are "value objects" by design > choice. A Name object, for instance: first, middle, last. If you're > working with a system that uses Name objects, they're likely to be > immutable by design. A customer changes their name? Create a new > object. Regardless of whether Ranges should rather be immutable or not, I plead for sticking with the current immutability. The reason is simply that a change of mutability of a class is a major change, which is likely to break a lot of code. Everybody that relied on a Range being immutable and thus stored an instance as member of his own classes might recognize the range suddenly changed when it's no longer immutable. > Some things are best treated "just like a number". Ranges are one of > them (they're just two numbers and a flag, after all). Some say > strings should be immutable as well, and I think it's a justifiable > position. Personally I prefer the approach Matz has taken with Ruby strings because of my experience with Java strings. It can be a major performance drawback if you have to create a new string for every change that you do to a string (yes, I know there is StringBuffer, but too many methods just return a String); and in some cases your memory might not even suffice. My 0.02 EUR... Kind regards robert