[swift-evolution] named parameters

Tino Heth 2th at gmx.de
Fri Jan 22 16:32:31 CST 2016


>> UIView.insertSubview(_:,belowSubview:) and UIView.insertSubview(_:,aboveSubview:) beg to differ. As do UIView.convertPoint(_:,toView:) and UIView.convertPoint(_:,fromView:). Need more examples? Take a look at UITableViewDelegate.
> 
> Agreed. I'm quite happy that Swift labels are effectively part of the method name and therefore consistently applied. Long parameter lists are easy to get lost in.

That's exactly my opinion: Labels help us — the computer doesn't care weather a function has a meaningful name or is called as "f231(4, true)"
Especially because of the benefit of labels, it's imho not necessary that the compiler enforces their use… but I think it's actually annoying to be forced to skip labels:

func printPowWithBase(base: Double, exponent: Double) {
	print(pow(base, exponent))
}
printPowWithBase(2, exponent: 3)

Easy to understand, works as expected — but would it hurt if

printPowWithBase(base: 2, exponent: 3)

would be accepted as well? Sure, "base:" is redundant, but who cares? And, as others already mentioned: For init, the first label is required…

Additionally, there is a hidden(?) feature in Swift that's imho quite cool:
The ability to call a function with a tuple containing the arguments
let args = (4.0, exponent: 4.0)
printPowWithBase(args)

In this case, you end up with a first parameter without any indication of its role.

Tino


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


More information about the swift-evolution mailing list