Why may we use “internal argument labels” in type annotations of closures, when they (seemingly) can never be accessed?

前端 未结 2 1052
遇见更好的自我
遇见更好的自我 2021-01-20 16:51

Background

This is naturally legal:

let closure: (Int, Int) -> () = { print($0 + $1) }
closure(1, 2) // 3

Whereas, since the i

2条回答
  •  悲&欢浪女
    2021-01-20 17:21

    There have been complaints, not unreasonable, that if you remove the ability to name the parameters, you lose an important aspect of the human communication that tells a future maintainer or user of this code the purpose of these parameters. Well, that ability has been removed as far as external parameter names are concerned. But by leaving it open to sneak past the compiler by using just internal parameter names, we recover at least something of that communication.

    However, we do not recover enough of that communication, because the internal parameters don't show up in code completion:

    This has been criticized as a flaw in the new regime on this matter, and, in my opinion, rightly so.

提交回复
热议问题