[Newbies] Re: A Question of Style

Tim Johnson trilobyte at hoe.nu
Sat Mar 31 17:08:08 UTC 2007


> I've seen the suggestions in other responses to this and I don't like
> them.
>
> Calling "everything" a setter/getter seems to be J-zeitgeist but, what you
> have here is a collection of prices, indexed by a symbolic key, rooted at
> instances of Vendor.
>
> Translated to Smalltalk language this is a variant of #at:put:
>
> Vendor>>priceAt: aSymbol put: newPrice
>
> Even more Smalltalk-ish, you'd have
>
>   aVendor pricebook at: aSymbol put: newPrice
>
> People with an education in Smalltalk will immediately understand what's
> happening when seeing a piece of your code which sends #priceAt:put:, even
> in the absence of class comments :)

Something I read in Smalltalk With Style, though, says that you should
hide the implementation details.  Your method names should not refer to
the data structures behind them.  Even though my Vendor's pricelist is a
Dictionary, I do not need to expose that implementation to the user of
Vendor.  Smalltalk With Style makes this very clear.  It definitely
prefers that I communicate with Vendor in the language of a Vendor, and
not in the language of a Dictionary.

It is similar to if I went to a GroceryStore.  I would not log in to their
SuperMainframe5000 and type in SQL code to query the price of an apple.  I
would ask their sales representative, "how much is an apple?"

Also, I am not a Java user so I am not trying to Java-tize Squeak :)

Thanks,
Tim



More information about the Beginners mailing list