From: dblack@... Date: 2007-08-15T20:48:53+09:00 Subject: Re: ! semantics Hi -- On Wed, 15 Aug 2007, Simon Krahnke wrote: > * (16:48) schrieb: > >>> That is true for Array#delete. delete is always destructive, there is no >>> need to flag that. >> >> And push, pop, <<, concat, replace, clear... > > Which all have to be modifying. With the exception of concat. (The Unix > cat command isn't modifying.) > >>> It should simply be clear from the name[0] if a method is destructive. >>> Often you need the ! for that, in some cases it's obvious without the !. >> >> I guess I take my cue from the Ruby core/standard language, where >> there's no use of !, as far as I know, except to distinguish a >> "dangerous" method from its non-dangerous partner. > > That's because of the completeness of the library. Whenever there can be > a non-modifying partner, there is one. ! does not mean modifying; it means "dangerous". > When you just define a modifying method, is not right to name it without > a ! just because you choose not to define a non-modifying version. I would never add a ! to a method name solely because it changes the receiver. That's a re-invention of what ! is for. > What if some other developer wants to add the non-modifying version? > He would have to rename your version. I think that's a solution in search of a problem. Just name your methods clearly, without !. Then, if you (or someone else) want to add a "dangerous" version, you can write the ! method. Also -- once again -- ! does not mean that the receiver is changed. It means "dangerous"; it's a warning to the programmer that the method is going to do something that the non-! version doesn't do, and that might involve the unexpected. ! is not a general-purpose receiver-modifying flag, and I would very strongly discourage its adaptation to that use. It's not necessary, and it dilutes the original purpose of !. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)