Named arguments
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Tue Oct 24 19:22:41 UTC 2017
On Tuesday, October 24, 2017 17:30:27 Andrey via Digitalmars-d wrote:
> Hello, why there are no named arguments for functions like, for
>
> example, in kotlin i.e.:
> > int sum(in int a, in int b) {
> >
> > return a + b;
> >
> > }
> >
> > sum(a = 1, b = 2);
Named arguments are not something that C-based languages typically have, and
D has a very strong C/C++ heritage. There are some folks who would like to
see them added to the language, but a DIP would have to be created and
approved by Walter and Andrei for that to happen. IIRC, in the past, Walter
didn't think that they interacted well with how D does function overloading,
but I don't know what he thinks now. Some folks have managed to implement
them using a library solution, and if you go digging in the
newsgroup/forum/mailing list history for "named parameters" or "named
arguments," you should be able to find discussions on that.
Personally, I don't want them in D. If you have enough arguments that it
matters, then the function probably has too many parameters or too many
similar parameters. And as a library writer, I don't want to have the
parameter names be part of the API. There are already enough problems
getting the type and function names right without having to worry about
bikeshedding over parameter names as well, and if we had named arguments,
then you couldn't change parameter names without breaking code. 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.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list