| |
| Posted by Unknown W. Brackets in reply to J Anderson | PermalinkReply |
|
Unknown W. Brackets
Posted in reply to J Anderson
| J Anderson wrote:
> bobef wrote:
>> and default parameters ( int func(int x=0) ) in the documentation...
>> anyone knows about this?
>>
> Not supported (I wish it was).
In my very humble opinion, *one* of these solutions should be available. Whether they are going to be inlined or not, having to make a dozen function definitions to "redirect" to other functions is a pain, and the way I program I use defaulting whenever possible.
As an example, PHP is rather good support for this - and many of the built in functions for it, as well as custom ones, have benefitted greatly. Perhaps the biggest advantage is:
Old function:
void doSomethingWith(int i);
New function:
void doSomethingWith(int i, bool specialCoolNewFlag = false);
In other words, it allows extension of pre-existing functions without losing the functionality. PHP has done this with functions such as print_r. (print readable, meaning format any variable in a very readable format, extremely useful for debugging.) In PHP 4.3.0, they added a flag "return" to it so you could chose to have the output RETURNED instead of outputted by the previously void function.
Right now you'd have to overload it with a quick function that just calls the non-overloaded version. And ugly way to get around the issue...
Defaulting is also useful when you have a parameter that is an array, and could be "none". It is logical to simply omit this parameter, instead of providing an empty array...
The entire Zend (PHP) API uses, basically, variable functions - meaning every PHP function that is written in C uses an array to store it's passed parameter list. But, it's an array of zval objects, which are basically variants - not really a built in thing.
This is why I think support for defaulted parameters would be terribly useful, and make variable argument lists (which are difficult to well implement..) unneccessary in most cases.
-[Unknown]
|