From: Bob Hutchison Date: 2005-10-18T22:51:24+09:00 Subject: Re: A couple of questions/statements from a Ruby neohacker On Oct 18, 2005, at 8:06 AM, Robert Klemme wrote: >> And that is *correct* use of the exclamation mark, because delete, by >> definition, can *only* be destructive. Since it is clear from its >> name that it is a dangerous method, the ! is unnecessary and unused. >> It's not a case of a broken convention, but of you misunderstanding >> the convention. >> >> Now you may disagree with that convention, and argue it should >> change. But you can't call that a convention break when it is not. >> > > I'm not so sure: the history of this list / ng has shown that this > issue > has irritated people over and over again. So the convention that was > followed in implementing this might be a different one from the > publicly > observed one. One reason for this might be that the term > "dangerous" in > this context is much broader and less precise than the term > "destructive" > (changing the receiver's state). Also "dangerous" is very context > sensitive (even IO#puts might be regarded as dangerous in certain > situations) which adds to the difficulty. It might be an interesting > philosophical debate which of the two conventions is more adhered > to, as a > convention is a social thing... This has been debated for years. I'll make a suggestion near the bottom of this post that I don't remember seeing on this list (but I wasn't paying close attention for a few years in there). I think there is a fundamental problem here. Scheme, a language with a lot of support for functional programming (in this case the aspect of fp to be emphasised is avoiding assignment or state change), is almost certainly where this convention originated. In scheme, a ! signifies that a state change may be made (i.e. an internal assignment). If we carry this through to ruby, which is an OO language that maintains object state (i.e. routinely modifies that state) then we are going to have a problem -- there are an awful lot of method names that should have a ! appended. Different languages have dealt with this differently. Eiffel, for example, does not allow methods that return a result to change an object's state, only method that have no result can do this, and on top of this you can't silently ignore results -- and so these methods are easily distinguished in that way. The presumption in eiffel is that if there is no result that state may change, not that it does change. However, Ruby is not Eiffel. So we use naming conventions and mark *some* destructive methods, normally only when there is a non- destructive alternative. Note that 'destructive' means simply that the object's state is changed, there shouldn't be any negative connotations understood beyond that -- in particular, 'destructive' does not imply 'dangerous'. It is conceivable that there is a connotation of 'surprise' here, but I think that is a mistake (one might even argue that the most surprising version is the non- destructive one). I think that there is no systematic way to deal with this, with just one marker, so that objections are never raised. Delete is the perfect example its non-destructive alternative -- which isn't defined in ruby -- would be something from enumerable, maybe reject with an equality test -- but no matter, it isn't named 'delete' and so there is no ! required. Given my druthers, I'd have considered a convention where when two methods are provided, one destructive the other not, to mark them both. There would be no marker if there is no choice. So we'd have something like 'action!' and 'action+' (or whatever, that second marker is another debate) and no method simply called 'action'. I'm not advocating anything here by the way. Other than perhaps that this is going to be a source of ambiguity, or perceived ambiguity (if there's a difference, and that's another debate :-) that keeps coming up. Cheers, Bob ---- Bob Hutchison -- blogs at Recursive Design Inc. -- Raconteur --