News 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

Daniel Krook's Blog: NYPHP Conference & Expo 2006

Syntux Blog: Advanced Caching Technique - Block Randomization

Justin Silverton\'s Blog: Flickr.com - PHP/mysql case study

PHPit.net: No more spam; Akismet and PHP to the rescue!

Soledad Penades' Blog: Signs your PHP needs refactoring


Community Events

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


version laravel release laravel5 unittest podcast introduction interview example voicesoftheelephpant php7 api extension series conference community opinion language framework library

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