Advertisement
Guest User

Untitled

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