[swift-evolution] Lambda function syntax

Alexander Regueiro alexreg at gmail.com
Tue Dec 22 18:08:54 CST 2015


>> I’ve also explained the big problem with trailing closures already. And closures are really *not* control flow statements, so treating like them is just a fallacy and source of confusion.
> 
> Trailing closures allow you to write constructs that look and act as if they were control flow statements, which in practice is quite useful.

It really just means you put the close bracket for a function call (parameter list) before the actual parameters end. Which not only doesn’t save any real space (2 characters if you’re lucky, but quite often 0), but it belies the semantics of passing arguments to function, at such trifling benefit.

> Closures do have control flow ramifications when reading code: the meaning of `return` inside a closure is different from its meaning in nearby code.

Sure, but that doesn’t mean closures are control-flow elements or statements. Also, I think my above point makes this rather irrelevant anyway.

> I personally favored `func` as the introducer for closures for precisely that reason. The presence of `func` would make it easier to recognize that there is something additional going on here, such as variable captures and `return` hijacking. Be warned that I lost that argument internally long ago.

Did you have anyone else on that side? :) I think if another public support can be drummed up, it should be on the cards again.

> 
>> There are other arguments against it too, like it doesn’t generalise well (at all) to multiple closure arguments.
> 
> The argument that a feature does not generalize becomes much weaker when the special case is important enough. Single-closure argument lists like map and dispatch… and with… are common enough that special treatment is warranted.

Sure, but then what's the benefit for single-closure argument lists in the first place? I still don’t say any. Honestly, it just looks like a confusing way to put the brackets in another place, at the cost of confusing people and making your function call look like a function definition. (Great!)




More information about the swift-evolution mailing list