Hi --
* <dblack@rubypal.com> (13:48) schrieb:
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".
Most methods flagged with a ! are dangerous because they modify their
receiver.
Many of them are, but there's no cause-and-effect between modifying
and !. If there were, there would be !'s on all modifying methods. I
think we should really put that to rest; the convention just doesn't
work that way, and never has.
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.
No, you add it because someone might else assume it is a non-modifying
method, that is what makes it dangerous.
Array#pop is modifying but not dangerous, because everyone expects it to
be modifying.
If the name doesn't connote destructiveness, then you should change
the name. For example, I would not use the name "last" instead of
"pop", because "last" does not connote destructiveness.
But I also wouldn't use "last!". Just adding a ! does not change a bad
name for a destructive method into a good name. It just adds a !.
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.
No, that's a problem.
Not really. If I have a "pop" method, and someone wants to write
"last" (i.e., return the last element but not destructively), they
don't have to write "pop!-minus-!". They should choose the best name,
which may have nothing to do with the name I gave the destructive
method.
In other words, m/m! is not the only possible ratio between methods.
There's also m/n, which can be just as close as m/m!. pop/last is an
example; so is concat/+ (also for arrays).
Just name your methods clearly, without !. Then, if you (or someone
else) want to add a "dangerous" version, you can write the ! method.
You are the one who's proposing that something isn't dangerous because
there currently isn't a less dangerous version.
I don't think I can quite follow all the convolutions we're getting
into
I've posted something about the ! on my blog, if anyone's
interested:
http://dablog.rubypal.com/2007/8/15/bang-methods-or-danger-will-rubyist
David
···
On Thu, 16 Aug 2007, Simon Krahnke wrote:
--
* 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)