News Feed
Jobs Feed
Sections




News Archive
Sameer Borate's Blog:
Refactoring 1 Consolidating Conditional Expressions
January 05, 2009 @ 09:31:08

Sameer has posted the first article in his "Refactoring" series today - a look at boiling down conditional expressions to only the logic that are really needed (and maybe replacing it all together).

Many times you see a group of conditionals where the returned values are the same. To make the code cleaner you can group the conditionals together using the '&&' or the '||' operators and then extract the code into a separate function. This also has the added benefit that you can reuse the extracted method in other places where the required conditional goes.

He shows how abstracting out a file upload permissions check to another function makes it easier to reuse and simpler to understand (an "if" versus multiple "return" statements).

0 comments voice your opinion now!
refactor conditional consolidate series


blog comments powered by Disqus

Similar Posts

Brandon Savage's Blog: Peer Review: Looking Into Abstraction

Richard McIntyre's Blog: Using OAuth in Lithium

Stefan Mischook's Blog: PHP Sessions Video Tutorials - Part 3

PHP Thinktank Blog: PHP-GTK with scottmattocks (IRC Talk Series)

PHP.net: PHP 4.4.6 Released


Community Events











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


introduction object framework zendframework2 tool language development phpunit conference podcast functional unittest example release testing series code community interview opinion

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