[swift-evolution] Make the first parameter in a function declaration follow the same rules as the others

Ted F.A. van Gaalen tedvgiosdev at gmail.com
Fri Mar 11 14:33:01 CST 2016


When I started using Swift (on the whole a pleasant journey)
the most confusing thing to me was, and at times still is,  the parameter list,


I would prefer:

-uniform for functions(…) AND init(…)
-every parameter must be used with its name/label. Always, no exceptions.
-no shortcuts. 
-allow arbitrary parameter sequence.
which is possible and very easy to implement when you always have to use names.
-no trailing commas.

Because you always have to specify parameter names/labels
it is easy to see (for the compiler) which parameters 
are omitted.

Omitting a parameter for which no default value was 
specified is still an error. 

The confusing # and _  are no longer necessary. 


‘inout’ and  external and local parameter names behavior remain as they are.

like so

     func foo(inout a: Type, b: Type = 12.34, c: Type)    // b may be omitted
 or
     func foo(a alocal: Type, b blocal: Type = 12.34, c: Type= 3.14159)    // b and c may be omitted    


 Valid calls:
    
    foo(a: v1, b: v2, c: v3)     // in sequence
    foo(c: v3, a: v1, b: v3)     // arbitrary parameter sequence is allowed.

    foo(c: v13)              // parms a and b are not present: default values wil be taken  
                                   // or error if no default specified.

Allow for more than 1 variadic parameter, why is this currently limited to one variadic parameter only? 
    
    foo(a: Type, b:Type…, c: Type…,d: Type)


   foo(v1,b: v2,c: v3) // this is an error: parameter name missing with first parameter.
          

It would end the confusion.


TedvG



More information about the swift-evolution mailing list