13.07.2015 Views

Smalltalk Best Practice Patterns Volume 1: Coding - Free

Smalltalk Best Practice Patterns Volume 1: Coding - Free

Smalltalk Best Practice Patterns Volume 1: Coding - Free

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Point>>printOn: aStreamaStreamprint: self x;nextPut: $@;print: self yHaving written this, I’m not sure why I prefer Cascades to the parenthesized format. Perhaps it’sbecause there is a big psychological difference in parsing a method with parentheses and onewithout. If I can avoid parentheses and still have a method that reads clearly, I will.Another use of yourself is with #inject:into:. Suppose you want to put all the children of acollection of parents together in a Set. You might be tempted to write:parentsinject: Set newinto: [:sum :each | sum addAll: each children]but this wouldn’t work, because the result of sending #addAll: is the argument (in this case thechildren), not the receiver. To get this to work as expected, you have to write:parentsinject: Set newinto: [:sum :each | sum addAll: each children; yourself]<strong>Coding</strong> <strong>Patterns</strong> page 138 of 147 9/30/2006

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!