Smalltalk linguistics (was: Re: Against wasteful forks)

Helge Horch Helge.Horch at munich.netsurf.de
Sat Mar 10 15:38:32 UTC 2001


At 19:40 09.03.2001 -0800, C. Keith Ray wrote:
>"Why Smalltalk? Smalltalk uses a simplified version of English.
>  Nouns and verbs. Object are the nouns.
>  Verbs are messages sent from one object to the next.
>  Easy as 1, 2, 3. It is no longer necessary to write cryptic programs.
>  This means that almost anyone can learn to write Smalltalk programs."
>                 - Peter William Lount
>
>I have to object to this quote. I picked a class at random, and here are a
>few of the method names of that class.  Where are the verbs?
>
>willingToBeEmbeddedUponLanding
>veryDeepInner:
>selectedItem
>popUpOwner
>popUpOwner:
>minHeightWhenEmpty
>items
>labels:lines:selections:
>itemWithWording:
>allWordings
>balloonTextForLastItem:
>defaultTarget:

Yup, these (and many other) selectors don't follow the observation that you 
cite.  Some selectors (like popUpOwner or stayUp) might even be 
misinterpreted if given out of context.

While one may certainly write code following such a guideline to the iota, 
the existing code does not.  I imagine it would be very wordy, riddled with 
common prefixes like "answer", "set" and "createNew". This would make the 
code harder to read.  After all, answering is a vital part of message sending.

A lot of selectors actually do support the object/noun rule, like e.g. 
"initialize", "detachSubMenu:" or "popUpInWorld".  Here are some common 
exceptions:

Getters and setters (also called accessors, methods that directly access 
instance state) are very commonly named like the "popUpOwner"/"popUpOwner:" 
pair.  Once you know this, you may choose to just recognize the scheme, or 
to insert a silent "'s" when reading code.  If you absolutely need verbs 
here, insert silent "answer" in the first case, and pronounce the colon as 
"be" in the second.  (This doesn't scale nicely to nested or cascaded sends...)

Queries (methods that make the instance answer a derived value, like 
"allWordings" or "itemWithWording:" above) often follow the getters scheme, 
so you may choose to insert a silent "answer" (or "answerWhether").

Some selectors lean towards the setter scheme ("labels:lines:selections:") 
for expressing the intention that multiple aspects of the receiver are set 
up.

Other selectors (like "veryDeepInner:") may not fit into a scheme at all; 
one may take that as a hint that they're either very special (indeed!), or 
badly named.

I usually recommend Kent Beck's "Smalltalk Best Practice Patterns" book for 
selector naming guidelines (and much more).

HTH,
Helge





More information about the Squeak-dev mailing list