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...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Type Suggesting Parameter NameYou are writing an Inline Message Pattern.What should you call a method parameter?There are two important pieces of information associated with every variable- what messages itreceives (its type) and what role it plays in the computation. Understanding the type and role ofvariables is important for understanding a piece of code.Keywords communicate their associated parameter's role. Since the keywords and parameters aretogether at the head of every method, the reader can easily understand a parameter's role withoutany help from the name.<strong>Smalltalk</strong> doesn't have a strong notion of types. The set of messages sent to a variable appearsnowhere in the language or programming environment. Because of this lack, there is no direct wayto communicate types.Classes sometimes play the role of types. You would expect a Number to be able to respond tomessages like +, -, *, and /; or a Collection to do: and includes:.Name parameters according to their most general expected class, preceded by "a" or "an".If there is more than one parameter with the same expected class, precede the class with adescriptive word.An Array that requires Integer keys names the parameters to at:put: asat: anInteger put: anObjectA Dictionary, where the key can be any object, names the parameters:at: keyObject put: valueObjectAfter you have named the parameters, you are ready to write the method. You may have to declareRole Suggesting Temporary Variables. You may need to format an Indented Control Flow. Youmay have to use a Guard Clause to protect the execution of the body of the method.<strong>Coding</strong> <strong>Patterns</strong> page 128 of 147 9/30/2006

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

Saved successfully!

Ooh no, something went wrong!