[Newbies] Are setters a good idea?
Blake
blake at kingdomrpg.com
Sun Sep 28 20:27:52 UTC 2008
On Sat, 27 Sep 2008 20:47:39 -0700, Ralph Johnson <johnson at cs.uiuc.edu>
wrote:
> On Sat, Sep 27, 2008 at 1:40 PM, Andy Burnett
> <andy.burnett at knowinnovation.com> wrote:
>> I read somewhere - can't remember where - that setters are considered
>> evil.
> This is not a good argument. Many Smalltalk objects are not modeled
> after the real world. Even if they are, is there really any
> difference between sprayPaint: aColour and colour: aColour?
>
> Setters are neither good nor evil. It is how you use them that is
> good or evil. Many people overuse setters. I try to avoid setters
> because it is harder to tell where a variable is modified if there is
> a setter. But sometimes they are just what you need.
If you're going to assign an action verb to a setter, it should be
reflective of the process.
donut := Donut makePlain.
donut ice: #chocolate.
donut addSprinkles: jimmies atRandom.
IMO.
More information about the Beginners
mailing list