Default argument values

div0 div0 at
Thu May 20 14:30:28 PDT 2010

Hash: SHA1

Adam Ruppe wrote:
> On 5/20/10, bearophile <bearophileHUGS at> wrote:
>> A default argument may be an arbitrary expression.
> What I do in code where I want this kind of behaviour is something like this:
> void func(Whatever* options = null) {
>     if(options is null)
>          options = Whatever(default blah blah);
> }
> (substitute null for any invalid amount for the parameter. I recently
> did some timezone functions that used int.min as the default offset,
> meaning load it from the global.)
> If I want to change the Whatever default, I change it there and it
> still works out. Nothing fancy required.
> On 5/20/10, Nick Sabalausky <a at a.a> wrote:
>> I dunno, a caller might rely on a default value being what it was when they
>> had compiled it.
> Eh, if you leave the argument off the list, you're saying "I don't
> really care what this is", so you shouldn't worry about changes... key
> word being "shouldn't". I know I've broken this rule before, so having
> to recompile at least would be nice, like you say.

Yeah, I've gone off default arguments, there is rarely a defensibly good
default argument, and you can achieve exactly the same functionality
with overloads.

C# dropped them, and when I do c# I don't miss default args.

Either way of doing them sucks; better just to have a properly
documented interface.

- --
My enormous talent is exceeded only by my outrageous laziness.
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla -


More information about the Digitalmars-d mailing list