What to do about default function arguments

Manu turkeyman at gmail.com
Thu Apr 26 15:58:22 PDT 2012


I've actually been making fairly extensive use of function/delegate default
args. I was pleasantly surprised when I realised it was possible.
Funnily enough, It's one of those things that I just expected should work
(as I find most things I just expect should work do in fact tend to work in
D), so it seems it was intuitive too at some level.

It would be a shame to see it go, but I wouldn't say it's critical, just
very handy. In my case, used in shared interface bindings. Occurs more
often than not in some interfaces.

On 26 April 2012 07:00, Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> On Wednesday, April 25, 2012 20:44:07 Walter Bright wrote:
> > A subtle but nasty problem - are default arguments part of the type, or
> part
> > of the declaration?
> >
> >     See http://d.puremagic.com/issues/show_bug.cgi?id=3866
> >
> > Currently, they are both, which leads to the nasty behavior in the bug
> > report.
> >
> > The problem centers around name mangling. If two types mangle the same,
> then
> > they are the same type. But default arguments are not part of the mangled
> > string. Hence the schizophrenic behavior.
> >
> > But if we make default arguments solely a part of the function
> declaration,
> > then function pointers (and delegates) cannot have default arguments.
> (And
> > maybe this isn't a bad thing?)
>
> Can function pointers have default arguments in C? Honestly, it strikes me
> as
> rather bizarre for them to have default arguments. I really don't think
> that
> they buy you much.
>
> If you use the function or delegate immediately after declaring it (as is
> typically the case when they're nested), then you could have just just put
> the
> default argument in the function itself and not have it as a parameter.
> And if
> you're holding on to a function or delegate long term, you're almost
> certainly
> going to be using it generically, in which case I wouldn't expect a default
> argument to make sense there often either.
>
> I'd vote to just disallow default arguments for function pointers and
> delegates.
>
> - Jonathan M Davis
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120427/79cc43d9/attachment.html>


More information about the Digitalmars-d mailing list