Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. Message: 11
  2. Date: Fri, 1 Jan 2016 14:21:35 -0800
  3. From: Ethan Diamond <[email protected]>
  4. To: Chris Lattner <[email protected]>
  5. Subject: Re: [swift-evolution] Closure Syntax
  6. Message-ID:
  7. <CA+TuH2kozmhFMVKWrjMarc0C9B_Z2mCB=D+GZ10=BC=Kj1fFLA@mail.gmail.com>
  8. Content-Type: text/plain; charset="utf-8"
  9.  
  10. FWIW I don't think the backlash to the use of ^ with Obj-C blocks was
  11. because of the carat itself, but because of the inconsistency of the syntax
  12. in different contexts. Sometimes the return type was after the ^, sometimes
  13. before. Sometimes you had to use (^). Sometimes the carat had the name of
  14. the block with it ^functionName. None of it fit in with the [object
  15. methodName] syntax of the language itself.
  16.  
  17. However, none of those problems exist with block syntax in Swift - it would
  18. be consistent all the way through. I guess what I'm getting at is that I
  19. hope when Swift was being designed that the carat syntax wasn't considered
  20. because of some benefit of the current syntax, and not from fear of the
  21. initial backlash from people who didn't like Obj-C block syntax. I can't
  22. speak to language design with respect to the compiler since I have no
  23. experience in that area, but from a programming perspective, there are a
  24. lot of benefits of block syntax over closure syntax and no benefits of
  25. closures over block syntax.
  26.  
  27. - Block syntax clarifies some hard to read function declarations such as:
  28.  
  29. func makeIncrementer(forIncrement amount: Int) -> () -> Int"
  30.  
  31. - There is no other syntax in Swift where the body's parameters are named
  32. inside the body. Everyone else has the ( inputs are named ) { body } syntax
  33. - (some of these are implied):
  34.  
  35. for (index in indices) { //Something with index }
  36. func doThing(index: Int) { //Something with index }
  37. if (let index = index) { //Something with index }
  38.  
  39. - You save the in keyword for for-in loops
  40. - I showed earlier how it allows for parameter naming when defining a
  41. closure type, which would be useful for autocompletion of blocks
  42.  
  43. Anyway, if closure syntax is unofficially set in stone then that's that. I
  44. still appreciate you taking the time to listen.
  45.  
  46. -E
  47.  
  48.  
  49.  
  50. On Thu, Dec 31, 2015 at 9:26 PM, Chris Lattner <[email protected]> wrote:
  51.  
  52. > On Dec 31, 2015, at 6:16 PM, Ethan Diamond via swift-evolution <
  53. >
  54. > *There are three pieces at play here IMHO:*
  55. > *1. How functions (global and on types) are declared and implemented*
  56. > *2. How function specifications are indicated as types*
  57. > *3. How anonymous functions are declared and implemented*
  58. >
  59. > Agreed, so lets flush out the rules a little more and see if we can find a
  60. > common language for all three, since they're interconnected. For the sake
  61. > of clarity, I'm going to refer to closures as blocks, since they're
  62. > effectively the same thing. I think we should begin with these three rules:
  63. >
  64. > 1. Let's try to keep precedent for function calls, since blocks are pretty
  65. > much functions
  66. > 2. A ^ signifies that we are now entering a block context with regards to
  67. > syntax
  68. > 3. Just as in a lot of the rest of Swift, let's infer information we can,
  69. > but optionally allow it to be respecified if it makes the syntax clearer
  70. >
  71. >
  72. > I can’t believe that you’re seriously considering use of ^ for closure
  73. > syntax, it is one of the most hated aspects of ObjC’s blocks. :-) :-)
  74. > FWIW, I’m the one to blame for the use of caret in ObjC’s block’s syntax.
  75. > In my defense, this was necessary to fit blocks into the C grammar -
  76. > everything everyone hates about blocks declaration syntax is shared with C
  77. > function pointer syntax. That "problem to be solved” doesn’t exist in the
  78. > Swift grammar, so I don’t see why we’d carry it over.
  79. >
  80. > More generally, we are extremely unlikely to make a change to the basic
  81. > declaration syntax of swift (e.g. func, var, etc) or closure expressions.
  82. > They have been carefully considered, and work well in practice. I don’t
  83. > see a reason to make a change here.
  84. >
  85. > -Chris
  86. >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement