[swift-evolution] [Proposal draft #2] Naming Functions with Argument Labels

Andrew Bennett cacoyi at gmail.com
Mon Jan 11 17:14:11 CST 2016


I'm for this proposal, but not for the syntax. If this proposal is mutually
exclusive with Bartlomiej's then I am -1 on Douglas'.

I was initially against _, but it is necessary to disambiguate cases like
this:

    naming a function: MyStruct.test(_),
    calling a function: MyStruct.test()

However I think that the syntax is closer to something we'd expect in
Objective-C than in Swift. I wonder if it would make sense to someone
unfamiliar with Objective-C.

Consider:
    struct MyStruct {
        static func test(a: Int, _ b: Int, _ c: Int) {}
    }
    MyStruct.test(1,2,3) // calling the function
    MyStruct.test(_:_:_) // naming the function

In this case I would expect to name the function like one of these:
    MyStruct.test(_,_,_)
    MyStruct.test(,,)

I would +1 this proposal if the syntax was like this:
    let fn1 = someView.insertSubview(_,aboveSubview:_)
    let fn = someView.insertSubview(_,at:_)

Instead of:
    let fn1 = someView.insertSubview(_:aboveSubview:)
    let fn = someView.insertSubview(_:at:)

I think it's more consistent with other *Swift* function syntax.
Additionally it is compatible with the syntax Bartlomiej proposes (see fn1).

Perhaps you can make the _ optional (for disambiguation), but commas should
be consistent with declaration/calling syntax.

On Tue, Jan 12, 2016 at 8:54 AM, Douglas Gregor via swift-evolution <
swift-evolution at swift.org> wrote:
>
>
> On Jan 11, 2016, at 1:53 PM, Tino Heth <2th at gmx.de> wrote:
>
> We discussed this a looooong while back and decided that we wanted the
‘_’ to emphasize that there is an argument there. The difference between
“foo(:bar:)” and “foo(bar:)” is barely visible.
>
> That is true, but I think it is very uncommon to have such a set of
methods — and afaics, it would violate the guidelines for method names.
>
> But speaking of additional characters that might be useful:
> What about the parameter types? When they are needed to identify the
exact function, it would be nice if they could be included as well.
>
> foo(bar:(Int))
> (that's why I wanted to avoid the parenthesis in the first place…)
>
>
> It’s grammatically ambiguous if you don’t have the “:)” at the end and,
IMO, it’s not important enough to have special syntax for this: one can
still coerce to a specific function type.
>
> - Doug
>
>
>
> _______________________________________________
> 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/20160112/17be14a2/attachment.html>


More information about the swift-evolution mailing list