Named arguments
bauss
jj_1337 at live.dk
Wed Oct 25 06:23:52 UTC 2017
On Tuesday, 24 October 2017 at 22:08:57 UTC, Jonathan M Davis
wrote:
> On Tuesday, October 24, 2017 13:36:00 H. S. Teoh via
> Digitalmars-d wrote:
>> On Tue, Oct 24, 2017 at 01:22:41PM -0600, Jonathan M Davis via
>> > It also wouldn't play well with separate compilation unless
>> > the parameter names were mangled into the function names,
>> > and symbol names in D are already too often too long due to
>> > idioms like Voldemort types creating really long symbol
>> > names. Recent work on the compiler has reduced that problem,
>> > but adding more information to mangled names would
>> > definitely not help.
>>
>> [...]
>>
>> Nah. Parameter names are a concept only necessary at
>> compile-time. All you need is to import the function
>> declaration with the right parameter names, and on the
>> caller's side the compiler will always emit the arguments in
>> the right order. So no need to mangle parameter names at all.
>
> Except that things get a bit interesting with regards to stuff
> like .di files. Without the parameter names being mangled in,
> it would be possible for the parameter names in the .di files
> to not match the ones in the .d files. It's possible for that
> now, but right now, it doesn't matter, whereas with named
> arguments, it would matter. To some extent, you could probably
> get away with it, because the code that compiles against the
> .di files wouldn't normally be compiled against the .d files or
> vice versa, but it means that switching whether you used the
> .di files or the .d files could break code, whereas now, it
> wouldn't.
>
> Now, .di files are kind of terrible to use anyway, but
> introducing named arguments would just make them even more
> fragile if the parameter names aren't part of the function's
> mangled name.
>
> - Jonathan M Davis
Pardon me, but I don't understand how named arguments can break
anything by being added, as long as you don't add an additional
syntax to the function declaration.
void foo(int bar, int baz)
{
}
in .di
void foo(int bar, int baz);
...
Can be called like:
foo(1, 2);
foo(bar: 1, baz: 2); becomes foo(1, 2);
foo(baz: 2, bar: 1); becomes foo(1, 2); because it matches the
argument index.
int bar = 1;
int baz = 2;
foo(bar, baz);
More information about the Digitalmars-d
mailing list