[swift-evolution] [Idea] Passing an Array to Variadic Functions

Dennis Weissmann dennis at dennisweissmann.me
Wed Apr 20 10:59:52 CDT 2016

Sorry for my absence.

> Increment/decrement operators, currying, tuple splat and even the C-style for loop have already been deprecated, and although I would have preferred to keep some of those constructs, I think it is good how progressive Swift is pushed forward ("would we add this feature now if it wasn't already there?”)

That is exactly my opinion.

Thanks Haravikk for compiling a list with pros/cons.

In my opinion, we have a perfectly fine way to express “a sequence of values”. And that is arrays. So why would you need a second concept to accomplish the exact same thing? In fact, inside the implementing function all varargs *are* arrays, why aren’t they outside?

The other reason I don’t like them is that, at the call site, you cannot distinguish between them and C functions (or badly named Swift functions).

Take the C stdlib atan2 function for example:

let a = atan2(3.0, 4.0)   

Does it take 2 Doubles? Or does it take a vararg list of Doubles. Can I do let a = atan2(3.0, 4.0, 5.0)? I cannot tell by reading someone else’s code (and there is quite a lot of C code out there).

Even in Swift it is possible to write functions like these:

func whichOne(t: Int) -> Int {
  return 1

func whichOne(t: Int...) -> Int {
  return 2

func whichOne(t: Int, _ t2: Int...) -> Int {
  return 3

Now call these functions:

whichOne(2, 2)
whichOne(3, 3)

Can you guess what they return? (answer: 1,3,3)

In the end it’s just another concept to learn (or at least to be aware of) which in and of itself does not create much of an added value (except you save two characters []).

- Dennis

> On Apr 20, 2016, at 4:56 PM, Tino Heth via swift-evolution <swift-evolution at swift.org> wrote:
>> The question is whether the downside to variadic parameters is really enough to justify _removing_ an existing language feature. 
>> The burden of justification should be on those people wanting to change the language, not on those wanting to maintain the status quo and “I don’t like it” or “I think it makes code a tiny bit less readable” is not sufficient justification, in my opinion because you already have the option not to use the feature. 
> Afaics, this isn't true:

> The value of variadic functions is imho less than the possibility to omit "()" in procedure calls, and afair, there have been several posts that illustrate the complications of this feature.
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

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

More information about the swift-evolution mailing list