Andrei Zmievski wrote:
On Jan 9, 2006, at 4:09 AM, Aidan Lister wrote:

As useful functions tend to increase in complexity over time, often so does the number of parameters.

It soon gets to the point where function calls look like:
foo(true, false, false, false, false, true)
The rest of the parameters being required to be supplied, with their default value, when the user is only interested in changing the last option.


If you get to the point where your function has a dozen parameters, I would suggest re-thinking the purpose and design of such a function, because you are likely trying to make it do too much.

-Andrei

In a simple highlighting function I wrote (which at 16k hits is probably considered useful) I needed most of the following parameters:

$text
$needle
$strip_links
$case_sensitive
$whole_word_only
$simple_text_only
$highlight_pattern
$return_or_print
$use_xhtml
$tooltips_or_divs

I imagine any function dealing with html may use a significant portion of these. Obviously some of these are for effect, but I think my point is clear enough.

We've discussed other options at developers disposal like associative arrays, setOpt and getOpt functions in a class, but again each have their drawbacks and named parameters solve the problem elegantly.

Could we properly discuss the pros and cons of a name parameters implementation - even if it's only to put the whole issue to bed once and for all?

Best wishes,
Aidan

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to