[swift-evolution] named parameters - why hidden first?/proposal interest

Tino Heth 2th at gmx.de
Fri Jan 22 08:26:42 CST 2016

> The other unfortunate thing about this, is that this is another instance where "init" behaves differently then the rest of Swift. I think it would be great to unify this.
It's definitely confusing that labels receive special treatment in init, and I'm quite sure method declarations would look different without the "Objective-C-legacy".

Imho named arguments with default values are a great feature, which I loved since I've seen it the first time R (which would be very hard to use without default values…).
R, as my reference, is quite flexible with parameters:
You can leave out all labels, and only rely on the order of the values, you can assign values in whatever order you like — and, up to a certain degree, you can mix:
myFunc(firstParameterWithoutLabel, secondParameterWithoutLabel, fourthLabel = 8, thirdLabel = 0.5)

I don't think Swift needs that much flexibility, but imho the compiler could be less strict and leave it to the user weather parameters are identified via label or position.

say("message", times: 4)
is a good default and should be offered by autocompletion, but

say(message: "Hello", times: 4)

and even

say("Hello", 4)

could be allowed as well (as long as there is no clash with a second say-function).

Labels are "just" an aid for programmers, but for the program itself, they have not much more meaning than a comment:
Higher-order functions already ignore labels completely and rely on positions only.

So, instead of complicated rules enforced by the compiler, I would prefer a simple system backed by conventions that discourage programmers to fall back to C-style calls where you have to count parameters to decipher their meaning.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160122/bec10284/attachment.html>

More information about the swift-evolution mailing list