Hi --

On Sun, 2 Dec 2007, Bill Kelly wrote:

>
> 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? :-) 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).

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.

The only standalone ! methods I can recall seeing that made sense to me
are the ones in Builder, by Jim Weirich, where the ! is a kind of
escape from having the method name be automatically used as the name
of an XML element. Come to think of it, those aren't really
standalone, since the equivalent non-! methods do exist.


David

-- 
Upcoming training by David A. Black/Ruby Power and Light, LLC:
    * Intro to Rails, London, UK, December 3-6 (by Skills Matter)
See http://www.rubypal.com for details and 2008 announcements!