News Feed
Sections




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

Jani Hartikainen's Blog:
A simple way to make your code better Stop adding more parameters
November 12, 2009 @ 11:19:08

Jani Hartikainen offers a simple suggestion for making your code better - stop adding more parameters.

You need to add some new functionality to your function or class. Let's say you need to remove all objects stored, but optionally also call a method on them. It's pretty simple, isn't it? Let's just add a parameter to removeAllObjects! If you make it true, the additional method is called, otherwise not. Except it's not really such a good idea at all...

He points out that there's nothing wrong with parameters, it's their overuse that can cause the issues - if, in using them, it's unclear what they're doing, don't use them. He includes a few rules for making good use of parameters: less is good, relationship to the function, parameter order importance and using the language's parameter handling to your advantage.

0 comments voice your opinion now!
parameters opinion better code


blog comments powered by Disqus

Similar Posts

RawSEO Blog: 5 reasons why oscommerce is a nightmare

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

Stanislav Malyshev: PHP 5.4 (Looking Back) & 5.6 (Looking Forward)

Codewalkers.com: New Tutorial - Coding \"Best Practices\" - or at least \"Better Practices\"

Perforce Software: Seven Pillars of Pretty Code


Community Events

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


release symfony2 interview performance community voicesoftheelephpant api opinion part2 podcast laravel example configure conference library php7 application series introduction framework

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