I am guessing early on in the development of the Swift language the relationship between a function declaration’s parameter labels and whether they need to be included in a call was much more forward.
Maybe it looked something like this.
Declaration | Call | Comment |
---|---|---|
func foo(x: Int) | foo(2) | Omit label |
func foo(#x: Int) | foo(x:2) | Use label |
func foo(_ x: Int) | foo(2) or foo(x:2) | Label optional |
func foo(bar x: Int) | foo(bar:2) | Use external label |
But then they decided that to make Swift play nice with Cocoa that labels would be required by default in classes, but not in standalone functions. As long as it wasn’t the first parameter in a member function, in which case the label was to be omitted. Unless it was an init
in which case all labels were required. Oh, and if it had a default value, whether it is a standalone function or a member function the label was to be required.
When all was said and done, we were left the situation as depicted by the binary decision tree below.
Perhaps something more straightforward could have been devised?