Function signature logic swift closure

According to Apple doc the first parameter of a function has its name identifier omitted by default thus the function

func do(something: String, else: String) {}


will be called using

do("first", else: "second")


However, in case where you declare a closure, it appears that the first parameter has to be named which is in contradiction with the documentation. Example:

func activatePlate(plate: String, activate: Bool, callback: (success: Bool) -> Void)
{
    Alamofire.request(.POST, "http://httpbin.org/post").responseData {
      response in
      callback(success: response.result.isSuccess) // <- why that
     // and not that -> callback(response.result.isSuccess)
    }
}

So you see in "activate" a clearer name as in "activatePlate"? 😕

Yes, exactly.

Let's keep in mind that if you want the argument to be unlabeled, there's nothing keeping you from writing:


func activate(_ plate: String)


It's all about the defaults which, as they are currently, are inconsistent and confusing to people new to the language.

My problem is not the label, it's the say-nothing-name activate instead of the clear activatePlate.

I find these kind of responses confusing. Obviously those working on Swift know that it could work the way you describe, but they've decided for now that it encourages better APIs if the “weird” way is the default. If you want to convince them to change the rule then arguments from this angle would be more persuasive.

This example is contrived; surely activate would be a method of Plate in real code. That said, let's for pedagogical reasons assume that we do have


func activatePlate(plate: String) // A robot will do this at dinner time?


Then, we can also have

func activatePlate(plate: String, and fork: Fork)

(you are probably suggesting that and should be andFork but I think that whatever is passed in should be recgognizable as a fork)


and

func activatePlate(plate: String, and fork: Fork, andThenAfterRinsingWithOil laterƒ: ()-> ())



The name of a function is not the part outside the parentheses. The name of a function is the entire sentence that takes into account every parameter. This is only not obvious when there are fewer than two paramters.


The problem comes in when naming closures that reference a function. Closures don't currently support overloading. They need to. They also need to support internal parameter names.

let activate: (plate: String) -> ()
let activate: (plate: String, and fork: Fork) -> ()


Of course, I don't believe in there being both functions and closures to begin with.

https://forums.developer.apple.com/thread/16594

let activate(plate: String) {}
let activate(plate: String, and fork: Fork) {}
Function signature logic swift closure
 
 
Q