Example Method in Beck's Smalltalk Best Practice Patterns

11 views
Skip to first unread message

bprior

unread,
Jul 3, 2013, 2:13:31 PM7/3/13
to isq...@googlegroups.com
Kent Beck uses this example on page 3 of his Introduction:

Part>>* aRate
     ^Part
           amount: amount * aRate
           date:date
Station>>computePart: aPart
     ^aPart * self rate

It looks like the method selector in the first line is * aRate.  I haven't seen this syntax before. Am I missing something? Or is it a typo? Or?

Johnmci

unread,
Jul 3, 2013, 2:19:26 PM7/3/13
to isq...@googlegroups.com
2*3

Someone has to implement the *

Say Integer>>* aNumber
 ^aNumber productFromInteger: self

PS double dispatch here 

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "isqueak" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isqueak+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Bert Freudenberg

unread,
Jul 3, 2013, 5:26:40 PM7/3/13
to isq...@googlegroups.com
It's not syntax but convention: Class>>selector means the selector implemented by Class. The actual method in the system browser would look like

* aRate
^...

- Bert -


Bruce Prior

unread,
Jul 4, 2013, 1:47:29 PM7/4/13
to isq...@googlegroups.com
Bert, I understand Class>>selector. But why has he included the asterisk? Isn't a selector name supposed to be one word? I'm assuming the asterisk is intended as the binary multiply method. Shouldn't it be be included only in the actual method?
Bruce


Bert Freudenberg

unread,
Jul 4, 2013, 8:09:36 PM7/4/13
to isq...@googlegroups.com
Rate>>* is just an example of Class>>selector. 

There are three kinds of selectors in Smalltalk: unary (single word, e.g. "5 negated"), binary (non-letters, e.g. "3 * 4"), and keyword (one or more words ending in a colon, e.g. "4 between: 3 and: 5"). So 'negated', '*', and 'between:and:' are valid selectors. 

- Bert -

Bruce Prior

unread,
Jul 5, 2013, 3:17:59 PM7/5/13
to isq...@googlegroups.com
Bert, thanks for this. Until now I didn't appreciate this view of the binary message characters as selectors. I've got it now. ("AhHa!")

Bruce

Bert Freudenberg

unread,
Jul 6, 2013, 2:49:17 PM7/6/13
to isq...@googlegroups.com
You're welcome. Btw, this sort of question would be very much appreciated on our beginners list - many others could learn from them:


- Bert -
Reply all
Reply to author
Forward
0 new messages