From: Gavin Sinclair Date: 2002-12-09T16:46:33+09:00 Subject: Re: [YANQ] -yet another (ruby) newbie question -string#concat From: "Pe�a, Botp" > > Not every method that modifies the receiver has a ! -- for > > example, String#replace. (If there were a replace!, then the > > original replace would just be dup :-) I guess to me > > 'concat' has the same inherently change-rendering implication > > Then #replace method is another thing I would avoid since the syntax/naming > has implications or assumptions. Syntax/Naming should be unambiguous as much > as possible, imho... Why can we not standardize on suffixing "!" on methods > that modifies objects? Are they too many? Though, this is not a big problem > for me really, as of now, since I'm actually avoiding them.. :-) Not every destructive method is marked with a ! because ...... ... I believe the benefit of the "!" notiation is to distinguish between methods that are similar in semantics but have the subtle difference that one modifies the recevier and the other does not. Thus, we are enriched by having: String#gsub String#gsub! Array#uniq Array#uniq! Kernel::chomp Kernel::chomp! for example. If we marked *every* destructive method with "!" then we would lose that quality about "!" which so distinguishes it as a language feature in the first place. As David wrote, Array#push! and String#replace! etc. would get a bit tiresome. Also note that most library classes do not contain many, if any "!" methods, because they do not need to make the distinction. A method either modifies the receiver or it doesn't. There's no use having one that does and one that doesn't. "?" methods are used in most Ruby code, though, because there is no distinction that can possibly be made between "Klass#method" and "Klass#method?". A method is either a predicate or it's not. "?" is just a very nice coding style that I'm very grateful for. Gavin