[swift-evolution] Removing Variadic Parameters.

Haravikk swift-evolution at haravikk.me
Thu Jul 7 03:07:58 CDT 2016

> On 6 Jul 2016, at 21:13, David Rönnqvist via swift-evolution <swift-evolution at swift.org> wrote:
> I'd be reluctant to remove variadic parameters. We've found on our team that variadic arguments are easier to read on the call site compared to array arguments, especially when it's common to pass a single value (but still possible to pass multiple values).
> - David

I'm very much in the remove-them camp, however I do wonder if there might be another way to handle them? In other words, when defining a method we should always define an array, but perhaps we could use an attribute to selectively turn any Sequence or Iterator parameter into a variadic, like-so:

	func someMethod(@variadic _ values:[Int]) { … }

This can be called using the developers preference between:

	someMethod([1, 2, 3, 4, 5, 6])
	someMethod(1, 2, 3, 4, 5, 6)

So long as there's no ambiguity of course. This should have a few advantages over the current variadics:

No unique declaration syntax
Reinforces that a variadic function is just a function taking some kind of Collection
Enables us to choose the type of the parameter from any Iterator, Sequence or Collection.
Allows developers to choose the function's form at the call-site between passing a collection/sequence/iterator or a list of values. Also an array literal if the chosen type supports that as in the example above.
Allows passing of an array literal or appropriate Collection type.
An attribute is more discoverable (option-click in Xcode to view documentation).

Any got any thoughts on this alternative?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160707/35af8619/attachment.html>

More information about the swift-evolution mailing list