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.

Explaining Temporary VariableTemporary Variable can be used to improve the readability of complex methods.How can you simplify a complex expression within a method?In the passion of the moment, you can write expressions within methods that are quite complex.Most expressions are simple at first. As soon as you are looking at live data, though, you realizeyour naive assumptions will never work. You add this complexity, then that one, then another,until you have many layers of messages piled on each other. While you are debugging it is allunderstandable because you have so much context. Coming back to such a method in six months isquite a different experience.Fixing the method right might require changes to several objects. While you are just exploring,such a commitment might be inappropriate.Take an identifiable subexpression out of the complex expression. Assign its value to atemporary variable before the complex expression. Use the variable in the complexexpression.Role Suggesting Temporary Variable Name explains how to name the variable. Composed Methodputs the subexpression where it belongs and gives it a name.<strong>Coding</strong> <strong>Patterns</strong> page 81 of 147 9/30/2006

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

Saved successfully!

Ooh no, something went wrong!