named arguments (C++) - Something D could learn from
Atila Neves
atila.neves at gmail.com
Tue Dec 18 10:44:28 UTC 2018
On Monday, 17 December 2018 at 21:11:03 UTC, JN wrote:
> On Sunday, 16 December 2018 at 22:16:28 UTC, Matthew OConnor
> wrote:
>>
>> I am a C++ developer by day and reading that article made me
>> cringe. C++ has this creeping, expansive, everything ends up
>> in the language or writable in it, if you accept awful
>> messages and contorting the syntax. I hope D doesn't go down
>> that route.
>
> Well that's the problem. If it was implemented as a language
> feature it'd be a clean solution with nice syntax. But trying
> to force it with templates will always look ugly.
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`.
More information about the Digitalmars-d
mailing list