named arguments (C++) - Something D could learn from

JN 666total at wp.pl
Tue Dec 18 11:01:25 UTC 2018


On Tuesday, 18 December 2018 at 10:44:28 UTC, Atila Neves wrote:
>
> IMHO, there's no point, just wrap every parameter in a struct. 
> Is there really that much of a difference between:
>
> displayCoolName(firstName = "James", lastName = "Bond")
>
> and
>
> displayCoolName(FirstName("James"), LastName("Bond"))
>
> ?
>
> It's not even fewer characters! It's not trivial but it's 
> possible to make the order not matter by using a templated 
> implementation and aliasing it to `displayCoolName`.

Well, but then you have to create structs for everything you want 
to pass to the method. And you have to explicitly define which 
arguments can be passed by name. In languages like C#, you don't 
have to mark arguments as named or anything like that, you just 
pass the names at the call site.


More information about the Digitalmars-d mailing list