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.

Inline Message PatternYou are about to write a method for an Intention Revealing Selector.How do you format the message pattern?One alternative is to write the keyword/argument pairs one per line. This makes it easy to see whatthe selector of the method is by reading straight down from the top left corner. However, this styleof formatting will often take up three or four lines of vertical space. Composed Methods aregenerally only a few lines long. It seems a waste of space to have more introduction than content.Another reason for lining up the keywords vertically is that early text editors did not have linewrapping, so if you wanted to see all the parameters you had to scroll horizontally. All current<strong>Smalltalk</strong>s have line wrapping available in the source code editor, so all arguments are availableregardless of window size or message pattern width.The problem of reading the selector as a whole is solved by the browser. You never look at amethod as a raw piece of text. Methods always appear in the context of a browser. The selector isalways presented near the method. If you forget what method you are working on a quick glanceabove the method will answer your question.By saving the vertical space otherwise taken up by the message pattern you can quickly scan manymethods in a smaller browser than is otherwise possible. This allows you to have more informationon the screen at the same time, if it is useful.Write the message pattern without explicit line breaks.I format message patterns like this:from: fromInteger to: toInteger with: aCollection startingAt: startIntegerI’ve seen this formatted like this:from: fromIntegerto: toIntegerwith: aCollectionstartingAt: startIntegeror worse:from: fromIntegerto: toIntegerwith: aCollectionstartingAt: startIntegerBoth of these spend vertical space, increasing the chance that you won’t be able to see the body ofthe method (the part that matters, and the part that is likely to be surprising) without scrolling.Use Type Suggesting Parameter Names for parameters.<strong>Coding</strong> <strong>Patterns</strong> page 127 of 147 9/30/2006

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

Saved successfully!

Ooh no, something went wrong!