[Newbies] names for boolean keyword arguments

Randal L. Schwartz merlyn at stonehenge.com
Sat Sep 27 01:05:28 UTC 2008


>>>>> "Norbert" == Norbert Hartl <norbert at hartl.name> writes:

Norbert> There is no strict rule to it but I think here the majority
Norbert> follows some "hint what to expect" rule. That means you name
Norbert> the argument after the class of the argument.

Norbert> expensive: anExpensive

If I recall, according to Smalltalk Best Practice Patterns (the seminal
patterns book for Smalltalk), you want the attribute to be of the form
"isProperty":

  isExpensive := true.

which means that "expensive:" shouldn't be a setter.  In fact, said book
states that you should have "be" methods:

  anObject beExpensive
  anObject beCheap

which would likely set isExpensive to true and false respectively, perhaps,
or even 2 states out of a 3-state variable.  Encapsulation!  Because
then you also have tests:

  anObject isExpensive ifTrue: [ ... ]

or even (if you use it a lot):

  anObject ifExpensive: [ ... ]

I've often argued that automatic creation of getters and setters is wrong.
This is clearly an example of where automatic getters and setters lead you to
bizarre code.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


More information about the Beginners mailing list