[swift-evolution] [Proposal Draft] parameter forwarding

Dany St-Amant dsa.mls at icloud.com
Tue Jan 12 22:25:35 CST 2016

> Le 12 janv. 2016 à 01:33, Chris Lattner via swift-evolution <swift-evolution at swift.org> a écrit :
> On Jan 11, 2016, at 6:00 PM, Matthew Johnson <matthew at anandabits.com> wrote:
>> Do you have any ideas for a better direction that could handle forwarding of default parameter values and / or a subset of parameters?  Or is tuple packing and unpacking the best we can hope for?
> There is no structural problems with mechanisms that take parameters and forward to other calls, e.g.:
> func f(a : Int, b : Float, c : String) {
>   bar(@@@ARGS@@@)   // obviously horrible to get the point across :-)
> }

Really horrible indeed, but this kind of forwarding have the advantage of not obfuscating the parameter list.

The magic behind the forwarding may make it faster to write code, and remove some clutter when the parameter list is exhaustive, but it may be slower to read it. Assuming, you are new to a project, and you look at the following function:

>>> func bar(...fooParams, ...foo2Params)
>>>  {
>>>     foo2(...foo2Params)
>>>     foo(i: 32, ...fooParams)
>>> }

How long does it take to find out how to invoke it? The auto-completion within Xcode can help, but what if you using a simpler text editor, or even only reading the code on the Web. In the proposal, the definitions of foo() and foo2() are closed by, but since not limitations are specified, the could be anywhere in the project requiring a possibly painful search for each of them.

Dany St-Amant

More information about the swift-evolution mailing list