News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHP-Coding-Practices.com:
Composing Methods Introduce Explaining Variable
July 02, 2007 @ 07:53:00

From the PHP-Coding_Practices.com 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

PHPMaster.com: Type Hinting in PHP

PHP-Coding-Practices.com: Composing Methods: Replace Temp With Query

Hasin Hayder's Blog: Did you know 'you can have cheese burger' could be a variable name?

Mike Naberezny's Blog: PHP Temporary Streams

NetTuts.com: Refactoring Legacy Code - Part 10: Dissecting Long Methods with Extractions


Community Events

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


language project api community application part2 symfony laravel introduction yii2 opinion composer example framework php7 interview programming list podcast series

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework