Skip to main content
Fix minor language errors and edit for readability
Source Link
let closure = { (args) -> ReturnT in ... } 

v.s.vs

func function(args) -> ReturnT { ... } 

Why didn't Apple follow the principle of Occam's razor and make closure and function declarations to be equal? For example, a closure could be defined like this:

let closure = (args) -> ReturnT { ... } 

This is how it is implemented in JavaScript and other scripting languages. This is also looks more reasonable because functionfunctions and closureclosures are actually identical. And, in contrary

In addition, putting arguments and the return type inside the brackets looks weird and could messconfuse a programmer.

let closure = { (args) -> ReturnT in ... } 

v.s.

func function(args) -> ReturnT { ... } 

Why didn't Apple follow principle of Occam's razor and make closure and function declarations to be equal? For example, closure could be defined like this:

let closure = (args) -> ReturnT { ... } 

This is how it implemented in JavaScript and other scripting languages. This is also looks more reasonable because function and closure are actually identical. And, in contrary, putting arguments and return type inside the brackets looks weird and could mess a programmer.

let closure = { (args) -> ReturnT in ... } 

vs

func function(args) -> ReturnT { ... } 

Why didn't Apple follow the principle of Occam's razor and make closure and function declarations equal? For example, a closure could be defined like this:

let closure = (args) -> ReturnT { ... } 

This is how it is implemented in JavaScript and other scripting languages. This also looks more reasonable because functions and closures are actually identical.

In addition, putting arguments and the return type inside the brackets looks weird and could confuse a programmer.

Tweeted twitter.com/StackProgrammer/status/784185642939015169
Source Link
kelin
  • 153
  • 7

Why closure declaration syntax in Swift is different from function declaration

let closure = { (args) -> ReturnT in ... } 

v.s.

func function(args) -> ReturnT { ... } 

Why didn't Apple follow principle of Occam's razor and make closure and function declarations to be equal? For example, closure could be defined like this:

let closure = (args) -> ReturnT { ... } 

This is how it implemented in JavaScript and other scripting languages. This is also looks more reasonable because function and closure are actually identical. And, in contrary, putting arguments and return type inside the brackets looks weird and could mess a programmer.