News for hackers. Stuff that matters.
Re:Be wary of functions which take several parameters of the... by goatinaboat on Friday September 27, 2019 @03:01AM (#21089213)
Did they fix the thing where the first argument can’t be named but the rest can? I kicked the tyres on Swift when it was new and that was a real turn-off.
Re:Be wary of functions which take several parameters of the... by ww520 on Friday September 27, 2019 @03:19AM (#21089313)
The first argument can be named just fine.

    func fn1(myLabel1 myParam1: int, myLabel2 myParam2: int) {
    }

    fn1(myLabel1: 123, myLabel2: 456)

    func fn2(_ myParam1Omitted: int, myLabel2 myParam2: int) {
    }

    fn2(123, myParam2: 456)
Re:Be wary of functions which take several parameters of the... by masklinn on Friday September 27, 2019 @07:28AM (#21090684)
Yes, however that wasn't the case before SE-0046 (Swift 3): the early iterations had much stronger ties to objective-c where the method "names" the first parameter, so the first parameter could not be labelled separately.

From Swift 3 onwards, parameters and their labelling is completely consistent.

GP is wrong in one place though (at least for swift 2, not sure for swift 1): you could label the first formal parameter explicitly, it just wouldn't be labelled by default (unlike other parameters). That is:

    func f(p1:p2:)
would define

    f(_:p2:)
but

    func f(p1 p1:p2:)
would define

    f(p1:p2:)
Also, just to make things weirder, this special-casing would not apply to initialisers.
Re:Be wary of functions which take several parameters of the... by masklinn on Friday September 27, 2019 @07:27AM (#21090671)
That was fixed in Swift 3.0 following the acceptation of SE-0046.

In Swift 1.0, this applied to methods but not functions as it was following up from Objectice-C (foo:bar:baz: would become foo(_:bar:baz)), in Swift 2.0 it was expanded to all callables, and in Swift 3.0 it was removed and to be specified explicitly making labelling completely consistent.

Re:Be wary of functions which take several parameters of the... by goatinaboat on Friday September 27, 2019 @08:01AM (#21090908)
Thanks!