News Feed

News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way
Composing Methods Introduce Explaining Variable
July 02, 2007 @ 07:53:00

From the site, Tim Koschuetzki has posted an interesting suggestion for developers working with long expressions to make thing simpler - substituting temporary variables for portions of the expression.

Introduce Explaining Variable is particularly useful with long if-statements. You can take each condition, introduce an explaining variable and the conditional logic will read very well. Another occasion is a long algorithm where each step in the calculation can be explained with a well-named temporary variable.

The method is basically the following - declare the temporary variable with part of the expression, replace where needed in the expression, repeat for other parts of the expression. In his example code, he demonstrates its use, pulling out portions of an equation to calculate an item's price to make it much more readable.

0 comments voice your opinion now!
method variable temporary compose substitution method variable temporary compose substitution

blog comments powered by Disqus

Similar Posts

Stoyan Stefanov's Blog: Reusing an existing database connection with MDB2

Tim Koschuetzki's Blog: Composing Methods: Remove Assignments to Parameters Understanding the Factory Method Design Pattern

Developer Tutorials Blog: PHP array_walk(): Run an array through a function Caching your pages with PHP

Community Events

Don't see your event here?
Let us know!

framework interview api introduction podcast install wordpress configure bugfix series library threedevsandamaybe community release developer laravel language code list application

All content copyright, 2014 :: - Powered by the Solar PHP Framework