Hi --

On Tue, 14 Aug 2007, Simon Krahnke wrote:

> * <dblack / rubypal.com> (14:07) schrieb:
>
>>> Your method should be called "apply!" because it's destructive.
>>
>> I could be wrong, but I think the convention (at least in core Ruby)
>> is that ! methods always come in a pair with the non-! version.  I
>> don't think there are any cases where there's just a method called m!
>> where the ! indicates destructiveness (or other "danger"). All the
>> unpaired destructive methods have non-! names.
>
> That is true for Array#delete. delete is always destructive, there is no
> need to flag that.

And push, pop, <<, concat, replace, clear....  There's definitely no
general guideline that destructive methods end in !.

(Of course String has both delete and delete! :-)

> But there is no need for your method to be destructive, so you need to
> tell the world about it.
>
>> I think this makes sense. If unpaired dangerous methods have !, it
>> sort of suggests that any time there isn't a !, the method is
>> non-dangerous, which in turn suggests non-destructive... and that
>> isn't true.
>
> 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. I don't know of any
case where a method is just considered "dangerous" in the abstract,
without comparison to another method.

Basically, I can't find any object for which this:

  obj.methods.grep(/!/).detect {|m| not obj.respond_to?(m.delete('!')) }

or similar tests with private methods, etc., returns a value.


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)