From: Gavin Sinclair Date: 2004-10-12T11:17:00+09:00 Subject: Re: Ruby Directions (was Re: quality of error messages) 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. 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. Gavin