From: "David A. Black" <dblack@rubypal.com>
The thing to remember is that ! methods always exist (or should
always exist) in a pair with non-! counterparts.
Hmm. That makes sense to me in general, but I wrote a ! method
recently that has no non-! counterpart. A non-! counterpart
wouldn't make sense in this case, and yet I feel the ! is reminding
me something special is going on with this method.
The particular case is a UI client library whose widgets are
hosted on a remote window server. The client is able to create
and initialize widget objects locally, without yet having
communicated with the remote server. Only when the instantiate!
method is finally called, do we go over the wire and instantiate
these widgets in the window server.
There is no non-! counterpart, but I feel the ! is very
appropriate for this method.
My immediate thought, as a user of the method, would be: why? 
Exactly. Then I would feel I've succeeded in using the bang
notation: "Why?" seems a reasonable question to ask when seeing
an unfamiliar bang method. (That such a method may or may not turn out to be paired with a non-bang method has no bearing on
this: one *still* has to ask Why? in either case!)
If
it's not part of a pair, then the ! is usually a sign that it should
be named something else -- something where the name itself tells you
about what's happening (like push and pop).
Eh... I actually did consider naming it "instantiate_on_remote" or
something... But in the context of using this particular library, I
like the name "instantiate!" even better. Sure, it's a matter of taste;
but it feels right to me - and I'm pleased ruby has allowed me this
form of expression.
I don't mean to sound like the ! police. It's just that I've never
seen a usage pattern that, in my opinion, came close to being as
useful and elegant as the one Matz employs and recommends. The
problem, basically, is that the ! itself has no meaning. It's not even
as meaningful as ?, which fairly clearly connotes a boolean. So the !
is entirely what we make of it, and I haven't seen any improvements to
the approach Matz takes among the variants of usage. As a general,
contextless warning sign, it's hopelessly unclear and impossible to
interpret. In !/non-! pairs, it starts to be able to say something.
I don't see how one can infer any particular meaning from requiring
! methods to be paired with non-! methods. Seeing an unfamiliar !
method always boils down to the same question: What in particular is
special or unusual about the behavior of this method? That such a
method may have a non-! pair seems only interesting from the standpoint of determining which method to use when writing the code
in the first place. When reading existing code, one either knows
what's special about a particular ! method, or one doesn't.
If I see exit! in code, does the mere existence of a non-! exit
automatically confer to me that the ! form is special because it,
"Exits the process immediately. No exit handlers are run." ?
No, I got that from `ri` ...
When I see an unfamiliar ! method, is my first thought, "say, I
wonder if this method also has a non-! equivalent?" I'm pretty sure
I just think: what does this method do, and what's special about it?
Maybe I should instead be asking what you had in mind when you said,
"In !/non-! pairs, it starts to be able to say something." What is
this something that is said by a paired !/non-! relationship?
Regards,
Bill
···
From: "David A. Black" <dblack@rubypal.com>
On Sun, 2 Dec 2007, Bill Kelly wrote: