Posted by Richard Lynch on 01/07/05 19:37
Jay Blanchard wrote:
> switch($action){
> /* several dozen cases to follow */
> case "foo":
> writing out all of the code
> break;
> }
>
> and this
>
> switch($action){
> /* several dozen cases to follow */
> case "foo":
> include that will handle processing this case
> break;
> }
Performance-wise, there is probably a minor 'loss' to the second one.
But the maintenance benefits of the secodn one FAR OUTWEIGHT the
performance question.
The only conceivable exception to that is if you *HAD* to put all of that
long code inside some loop that runs a zillion times... You've got bigger
problems to solve if you're doing that anyway.
> Correct me if I am wrong, but includes (and/or requires) will get all of
> the code in all of the cases regardless if the case is being processed.
That got covered in depth already.
> etc
One thing I will say:
When I first started with PHP, I did this, because I was coming from a
desktop application background.
But it ends up being not all that maintainable, and you end up having to
open up and track too many files with too many interactions when you go
down this route.
I abandoned this style and have never regretted it.
YMMV
--
Like Music?
http://l-i-e.com/artists.htm
[Back to original message]
|