News Feed
Sections




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

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

Padraic Brady's Blog: More OpenID (in PEAR and Refactoring)

Anthony Ferrara: Programming With Anthony - Encryption

SitePoint PHP Blog: Build Virtual Machines Easily with PuPHPet Part 2

PHPClasses.org: Lately in PHP podcast episode 41 - What Happened in the Security Attack to PHP.net?

Richard McIntyre's Blog: Weaving Lithium #li3 into a legacy PHP application incrementally


Community Events





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


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

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