News Feed
Jobs Feed
Sections




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

Debuggable Blog:
Code Insults Round 1 - Why switch blocks are dumb
October 29, 2008 @ 08:48:28

In the first of his "I will insult your code" series, Nate Abele looks at this submitted code and points out that maybe blocks of switch/case statements aren't such a good idea after all.

The entire submission is actually two files, which together comprise a console script for interacting with a web service (the names of the entrants have been withheld to protect the identities of the guilty). Rather than examine the full entry, we're going to take a look at one part which I find comes up fairly often: switch block overkill.

The example he's talking about has a switch statement with eight different cases under it, most of them just setting two properties on the current class. Its used ot map command line parameters to their correct properties. Nate suggests a bit different method - still using switch/case but pulling the properties to be assigned from an array of options rather than hard-coding them into the evaluation.

0 comments voice your opinion now!
switch case block insult refine overkill property


blog comments powered by Disqus

Similar Posts

PHPMac.com: Two New Tutorials (Switch Navigation & A Simple Login)

Matthew Weir O'Phinney's Blog: Cgiapp2 Tutorial 1 - Switch Template Plugins at Will

SitePoint PHP Blog: Hot PHP UTF-8 tips

DZone.com: CakePHP - Web Test Cases with SimpleTest

Brent Meshier's Blog: Blocking visitors by country using PHP & MySQL


Community Events











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


symfony2 composer podcast application language opinion code package unittest threedevsandamaybe release facebook introduction overview framework hack component install hhvm security

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