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

Cal Evans' Blog: Six ways to be a better client for your developer - Point 8

Rob Thompson's Blog: Switch vs. If

Debuggable Blog: Code Insults Round 1 - Why switch blocks are dumb

Chris Hartjes' Blog: Metatesting: Extending Your Testing Tools

Label Media Blog: Design Patterns in PHP - Decorator Pattern


Community Events





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


install opinion unittest list composer series laravel conference community configure podcast api interview symfony language introduction voicesoftheelephpant release extension framework

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