Greg McIntyre wrote:
> Maik Schmidt <contact / maik-schmidt.de> wrote:
> > Greg McIntyre wrote:
> > > It bugs me that some methods have a ! on the end and some don't. It
> > > seems very arbitrary and inconsistent to me. And the same for ?.
> > 
> > Hmm, maybe the whole thing is much simpler than you think:
> > 
> >  From matz' "Ruby in a nutshell":
> > 
> > <quote>
> > You can append ! or ? to the name of a Ruby method. Traditionally,
> > ! is appended to a method that requires more caution than the variant
> > of the same name without !. A question mark ? is appended to a method
> > that determines the state of a Boolean value, true or false.
> > </quote>
> 
> Yes, but it wasn't until about 15 minutes ago that I understood why, in
> the standard library, some methods have ! and some don't. That is, what
> the actual rationale is. I'm not talking about capability, I'm talking
> about actual practice. Until 15 mintues ago, it just seemed like
> inconsistent use. And there is still some inconsistency. I think
> Array#delete_if should be Array#delete_if!, for example.

My understanding is, that "delete" is a destructive word itself, so it doesn't
need to be marked explicitly as "dangerous". If you need a non-destructive
delete_if version, better use the Enumerable#reject method, which IMHO
describes better it's internal sematics. Here, it's destructive counterpart,
reject! exists.

Your suggestion is that delete_if does not delete anything (it creates a new
array), where delete_if! would. Principle of Least Surprise? Not for me!


Regards, 

  Michael