Named parameters

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 24 14:11:19 PDT 2015


On 7/24/2015 1:11 PM, Jonathan M Davis wrote:
> On Friday, 24 July 2015 at 19:59:17 UTC, Shammah Chancellor wrote:
>> On Friday, 24 July 2015 at 19:45:55 UTC, Jonathan M Davis wrote:
>>> On Friday, 24 July 2015 at 14:15:11 UTC, Shammah Chancellor wrote:
>>>> Since D has optional arguments -- why don't we support named parameters?
>>>> There are extremely handy and work beautifully in languages like C#.
>>>
>>> We've argued about this several times in the past. We're not adding them.
>>> They interact badly with overloading (especially if you try and add more
>>> overloads later), and they make it so that the parameter names are part of
>>> the API, which means even more bikeshedding and arguments about naming.
>>>
>>> - Jonathan M Davis
>>
>> Funny, they work beautifully in C#.
>>
>> https://msdn.microsoft.com/en-us/library/dd264739.aspx
>
> Well, I don't know how C# dealt with mixing function overloading with named
> arguments (I haven't read the article yet)

Here's what it says:

-----------------
Use of named and optional arguments affects overload resolution in the following 
ways:

•A method, indexer, or constructor is a candidate for execution if each of its 
parameters either is optional or corresponds, by name or by position, to a 
single argument in the calling statement, and that argument can be converted to 
the type of the parameter.


•If more than one candidate is found, overload resolution rules for preferred 
conversions are applied to the arguments that are explicitly specified. Omitted 
arguments for optional parameters are ignored.


•If two candidates are judged to be equally good, preference goes to a candidate 
that does not have optional parameters for which arguments were omitted in the 
call. This is a consequence of a general preference in overload resolution for 
candidates that have fewer parameters.
--------------------

D already has plenty enough overloading rules, UFCS, overloading templates with 
non-templates, default values, constraints, overriding, 
covariance/contravariance, auto ref, etc., enough to thoroughly confuse everyone 
already :-)




More information about the Digitalmars-d mailing list