I haven&#39;t looked at the proposal extensively, but I like the overall direction. One thought about syntax. If it goes through, I hope that it does not use the #. I like how it&#39;s similar to the closure capture list now, and it doesn&#39;t seem to belong to a macro system. To me, it&#39;s in the same category as the capture list.<br><div class="gmail_quote"><div dir="ltr">On Thu, Feb 11, 2016 at 6:15 AM Taras Zakharko via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><blockquote type="cite"><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"><li>What is your evaluation of the proposal?</li></ul></blockquote></div><div style="word-wrap:break-word"><div>I agree with a number of people that have already replied before me: I think this is a very exiting proposal, but as it is right now, its not 100% fleshed out. Chris and other already provided comments on a number of points that also came to my mind. Specifically, I am not very keen on the proposed v.[foo] syntax and also the declaration of behaviours looks off to me as well (even though its elegant in its own right). I’d prefer something like</div><div><br></div><div>property behavior foo&lt;valueType: Value, instanceType: Self where …&gt; {</div><div><br></div><div>}</div><div><br></div><div>e.g. where we take the already available generics syntax and extend it with arguments to signal that behaviours are generics over multiple specific dimensions (this can be also used for a future extension of generic types). Required initial value can be coded by a presence of a constructor that takes mandatory argument, for example, or by an attribute as Chris suggests.</div><div><br></div><div>One potential problem with a feature like this is that it is very fundamental —it affects many areas of the language, some of those in a non-trivial way. These things are hard to get from the first go. I’d suggest that one makes an experimental implementation first and lets a bunch of people test-drive it for a couple of weeks or even months. I am sure that there will be some subtle design decisions that one might regret later. </div><div><br></div><div>So yes, its a definitive +1 but of the kind “revise and resubmit”. Also, sole real-world testing should be done before feature like this is be accepted into the core language. I also believe that fundamental, non-trivial features like these are best designed in a team. </div></div><div style="word-wrap:break-word"><div><br></div><blockquote type="cite"><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"><li>Is the problem being addressed significant enough to warrant a change to Swift?</li></ul></blockquote></div><div style="word-wrap:break-word"><div>Yes. it makes the language more consistent and flexible, while removing idiosyncrazy. I am also sure that it will open up new possibilities for the UI framework teams to come up with great APIs :)</div></div><div style="word-wrap:break-word"><br><blockquote type="cite"><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"><li>Does this proposal fit well with the feel and direction of Swift?</li></ul></blockquote></div><div style="word-wrap:break-word"><div>Yes, definitely </div></div><div style="word-wrap:break-word"><br><blockquote type="cite"><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"><li>If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?</li></ul></blockquote></div><div style="word-wrap:break-word"><div>I have used Python that has a very similar feature (property descriptors) quite extensively, and I have implemented many different patterns using this mechanism (such as property observing and binding). I have also implemented something similar for R.  I believe that Joe’s proposal is much better thought out and fits the overall theme of a strongly typed language very well. </div></div><div style="word-wrap:break-word"><br><blockquote type="cite"><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"><li>How much effort did you put into your review? A glance, a quick reading, or an in-depth study?</li></ul></blockquote></div><div style="word-wrap:break-word"><div>A quick reading. I was also following the discussion, but its a bit difficult to keep up — watching the swift-evolution list is more like a full-time job :)</div></div><div style="word-wrap:break-word"><div><br></div><div>— Taras</div></div><div style="word-wrap:break-word"><div><br></div><div><blockquote type="cite"><div>On 11 Feb 2016, at 07:13, Chris Lattner via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word">On Feb 10, 2016, at 2:00 PM, Douglas Gregor via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br><div><blockquote type="cite"><span style="color:rgb(119,119,119);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)">Proposal link:</span><br><div><div style="word-wrap:break-word"><blockquote style="margin:0px 0px 16px;padding:0px 15px;color:rgb(119,119,119);border-left-width:4px;border-left-style:solid;border-left-color:rgb(221,221,221);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"><blockquote style="margin:0px 0px 16px;padding:0px 15px;border-left-width:4px;border-left-style:solid;border-left-color:rgb(221,221,221)"><div style="margin-top:0px;margin-bottom:0px"><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0030-property-behavior-decls.md" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0030-property-behavior-decls.md</a></div></blockquote><p style="margin-top:0px;margin-bottom:16px"><a href="https://github.com/apple/swift-evolution#what-goes-into-a-review-1" style="font-size:1em;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1.1" target="_blank"><u></u><u></u><u></u><u></u></a><span style="color:rgb(51,51,51);font-size:1em">What goes into a review?</span></p></blockquote><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)">The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:</p><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"><li>What is your evaluation of the proposal?</li></ul></div></div></blockquote><div>I’m +1 on the feature.  I have some comments for discussion though, I’m sorry I didn’t get these to you before the formal proposal went out:</div><div><br></div><div><br></div><div><br></div><div>First, on the most obvious bikeshed, the surface level syntax proposed:</div><div><br></div><div><span style="white-space:pre-wrap">        </span>var [lazy] foo = 1738</div><div><span style="white-space:pre-wrap">        </span>foo.[lazy].clear()<br><br></div><div><br></div><div>Given the recent trend to use # for compiler synthesized / macroish / magic syntax, it is worth considering whether:</div><div><br></div><div><div><span style="white-space:pre-wrap">        </span>var #lazy foo = 1738</div><div><span style="white-space:pre-wrap">        </span>foo.#lazy.clear()</div><div><br></div></div><div>might make sense, or even:</div><div><br></div><div><div><span style="white-space:pre-wrap">        </span> #lazy var foo = 1738</div><div><br></div></div><div>I think that something like this is a bit better aesthetically, since the [] delimiters are heavily array/collection/subscript-centric (which is a good thing).  OTOH, this would be giving users access to the “#” namespace, which means that future conflicts would have to be resolved with backticks - e.g. if they wanted a “line” behavior, they’d have to use &quot;var #`line` foo = 1738”. I guess the fact that we already have a solution to the imagined problem means that this isn’t a big concern in practice.</div><div><br></div><div>In any case, I think we should just pick a syntax, land the feature, and keep bikeshedding on it through the end of Swift 3 :-)</div><div><br></div><div><br></div><div><br></div><div>What are the semantics of behaviors applied to var/let decls with non-trivial patterns?  For example:</div><div><br></div><div><span style="white-space:pre-wrap">        </span>var [lazy] (foo, bar) = qux()</div><div><br></div><div>?  While we could devise semantics for this in some cases, I think it is reasonable to only allow behaviors on single-identifier patterns, and reject the other cases as invalid.  If you agree, please loop that into the proposal.</div><div><br></div><div><br></div><div><br></div><div>I understand the need to specifying whether the getter/setter and other random methods are mutating or not, but doesn’t this eliminate the difference between a var/let behavior?  Couldn’t we just say that a behavior with a nonmutating getter &amp; setter are valid on a “let”, and that any other mutating members are unavailable on a let?  This seems like a theoretical win, though I’m not sure whether it would actually be a win in practice for any conceivable behaviors you’ve been thinking about.</div><div><br></div><div><br></div><div><br></div><div>I like the approach of having a behavior decl, but am not excited about the decl syntax itself:</div><div><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51)">behavior <span style="color:rgb(167,29,93)">var</span> [<span style="color:rgb(167,29,93)">lazy</span>] _: Value <span style="color:rgb(167,29,93)">=</span> initialValue {
</pre><div><br></div></div><div>I understand that this is intended to provide a template-like construct, but I have a few problems with this:</div><div><br></div><div>1) A number of the things here are actually totally invariant (e.g. the _, the colon) or only serve to provide a name (Value, initialValue) but cannot be expanded into general expressions, though they look like they are.</div><div><br></div><div>2) This is totally unprecedented in Swift.  We have a very regular structure of “@attributes decl-modifiers introducer_keyword name” - we have no declarations that look like this.  For example, while operator decls could follow this structure, they don’t.</div><div><br></div><div>3) If you agree that we don’t need to differentiate between var/let then “behavior var&quot; is providing potentially misleading info.</div><div><br></div><div>IMO, the most regular decl structure would be:</div><div><br></div><div>@initial_value_required      // or something like it.</div><div>property behavior lazy {      // could be “subscript behavior” at some point in the future?</div><div>   var value: Self? = nil        // Self is the property type?  Seems weird if it is the enclosing type.</div><div>   ...</div><div>}</div><div><br></div><div>or perhaps:</div><div><br></div><div><div>@initial_value_required</div><div>property behavior lazy&lt;PropertyType&gt; {  // specify the type of the property as a generic constraint?</div><div>   var value: PropertyType? = nil   </div><div>   ...</div><div>}</div><div><br></div></div><div>though I agree that this would require us to take “behavior” as a keyword.  Do we know whether or not this would be a problem in practice?  If so, going with “behavior var” and “behavior let” is probably ok.</div><div><br></div><div><br></div><div>Of course, @initial_value_required is also pretty gross.  The alternative is to follow the precedent of operator decls, and introduce random syntax in their body, such as:</div><div><br></div><div><div>property behavior lazy&lt;PropertyType&gt; {</div><div>   initializer initValue</div><div>   var value: PropertyType? = nil   </div><div>   …</div><div>       value = initValue</div><div>   ...</div><div>}</div><div><br></div></div><div><br></div><div><br></div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51)">  <span style="color:rgb(150,152,150)">// Behaviors can declare storage that backs the property.</span>
  <span style="color:rgb(167,29,93)">private</span> <span style="color:rgb(167,29,93)">var</span> value: Value?
</pre><div><br></div></div><div>What is the full range of access control allowed here?  Is there any reason to allow anything other than “public” (which would mean that the entity is exposed at whatever the properties access control level is)?  If so, why allow specifying internal?  For sake of exposition in the proposal, it seems simplest to say:</div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51)"><span style="color:rgb(167,29,93)">var</span> value: Value?  // private by default</pre><div><br></div></div><div>or something.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51)">  <span style="color:rgb(150,152,150)">// Behaviors can declare initialization logic for the storage.</span>
  <span style="color:rgb(150,152,150)">// (Stored properties can also be initialized in-line.)</span>
  <span style="color:rgb(167,29,93)">init</span>() {
    value <span style="color:rgb(167,29,93)">=</span> <span style="color:rgb(0,134,179)">nil</span>
  }</pre><div><br></div></div><div>If a behavior has an init() with no arguments, then are the semantics that it is *always* run?  What if there are both an init() and an init(value : Value)?</div><div><br></div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51)"> <span style="color:rgb(150,152,150)">// Inline initializers are also supported, so `var value: Value? = nil`</span>
  <span style="color:rgb(150,152,150)">// would work equivalently.</span>
</pre><div><span style="color:rgb(150,152,150)"><br></span></div><div>This example is using a stored property of type Optional&lt;Value&gt; which has a default value of nil, does that count or is this a syntactic requirement?  To me, it seems most natural to follow the existing rules we have:</div><div><br></div><div>1) If you write any init, then you get what you write.</div><div>2) If there are no init’s, and any stored property in a behavior is non-default initializable, then it is an error.</div><div>3) If there are no init’s, and all stored properties in a behavior are default initializable, then you get init() implicitly.</div><div><br></div></div><div><br></div><div><br></div><div>Typographical comment:</div><div><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51)">    <span style="color:rgb(167,29,93)">if</span> <span style="color:rgb(167,29,93)">let</span> value <span style="color:rgb(167,29,93)">=</span> value {
      <span style="color:rgb(167,29,93)">return</span> value
    }
</pre><div><br></div><div>You have way too many “value”s floating around, for sake of clarity, how about:</div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51)">    <span style="color:rgb(167,29,93)">if</span> <span style="color:rgb(167,29,93)">let</span> valuePresent <span style="color:rgb(167,29,93)">=</span> value {
      <span style="color:rgb(167,29,93)">return</span> valuePresent
    }
</pre></div><div><br></div></div><div><br></div><div>In &quot;Resettable properties”, you have this:</div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51)">  <span style="color:rgb(150,152,150)">// Reset the property to its original initialized value.</span>
  <span style="color:rgb(167,29,93)">mutating</span> <span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">reset</span>() {
    value <span style="color:rgb(167,29,93)">=</span> initialValue
  }</pre><div><br></div><div>This raises the question of how “initialValue” works:  Is it evaluated once when the property is bound and the resultant value is stored somewhere (evaluating any side effects exactly once) or is it an auto-closure-like concept?  If it is autoclosure-like, what does it mean in terms of requiring “self.&quot; qualification &amp; @noescape?</div><div><br></div><div><br></div><div>In the context of your @NSCopying-replacement example, I would want something like this:</div><div><br></div><div>class Foo {</div><div>  var [copying] myproperty : NSString</div><div><br></div><div>  init(a : NSString) {</div><div>     myproperty = a</div><div>  }</div><div>}</div><div><br></div><div>to work, where the behavior requires an initial value, but that value is provided by a flow-sensitive initialization point by DI .  How does this happen?</div></div><div><br></div><div><br></div><div><br></div><div><div><span style="color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)">&quot;This imposes an </span><strong style="color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px">initializer requirement</strong><span style="color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"> on the behavior. Any property using the behavior must be declared with an initial value&quot;</span></div><div><br></div><div>Ah, this gets to the @NSCopying replacement example.  This might be too limiting, but so long as there is a path forward to generalize this, it seems like a fine starting point.</div><div><br></div><div>[[Coming back to this after reading to the end]] Ok, I see this is in the future directions section.  I’m fine with punting this to a further revision of the proposal, but I think that it is worthwhile to provide a syntactic affordance to differentiate properties that “must have an initializer expression” and “must be initialized by an &#39;init(v: Value)’ member on the behavior before otherwise used”.  @NSCopying replacement seems like the later case.  I’m fine with pushing off the general case to a later proposal, but we should carve out space for it to fit in.</div><div><br></div><div><br></div></div><div><br></div><div><div><br></div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51)"><span style="color:rgb(167,29,93)">public</span> behavior <span style="color:rgb(167,29,93)">var</span> [changeObserved] _: Value <span style="color:rgb(167,29,93)">=</span> initialValue {</pre><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51)">...
   
    <span style="color:rgb(167,29,93)">if</span> oldValue <span style="color:rgb(167,29,93)">!=</span> newValue {
</pre></div><div><br></div><div><br></div><div>This makes me vaguely uncomfortable, given that “changeObserved” has undeclared type requirements that are only diagnosed when the behavior is instantiated.  I’d greatly prefer to see something like:</div><div><br></div><div><div>@initial_value_required</div><div>property behavior changeObserved&lt;PropertyType : Equatable&gt; {  // constraint specified!</div></div><div><br></div><div>which would allow the behavior to be modularly type checked.</div><div><br></div><div>[[later…]] ah, I see that you’re doing something similar but different in the &quot;Synchronized Property Access” example.  I mostly care that we can express and modularly check this, the exact syntax isn’t as important.</div><div><br></div><div><br></div><div><br></div><div><br></div><div>In detailed design:</div><div><pre lang="text" style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:16px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;color:rgb(51,51,51)"><code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;padding:0px;margin:0px;background-color:transparent;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;border:0px;display:inline;line-height:inherit;word-wrap:normal">property-behavior-decl ::=
  attribute* decl-modifier*
  &#39;behavior&#39; &#39;var&#39; &#39;[&#39; identifier &#39;]&#39; // behavior name
  (identifier | &#39;_&#39;)                  // property name binding
</code></pre></div><div><div>If you go with this declaration syntax, I’d suggest requiring _ for the name, since the name isn’t otherwise used for anything.  Ah, it looks like you say this later, maybe the grammar just needs to be updated?</div><div><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"><li>A <code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">_</code> placeholder is required in the name position. (A future extension of behaviors may allow the property name to be bound as a string literal here.)</li></ul></div><div><br></div></div><div><br></div><div><br></div><div><br></div><div><span style="color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)">&quot;Inside a behavior declaration, </span><code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;color:rgb(51,51,51)">self</code><span style="color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"> is implicitly bound to the value that contains the property instantiated using this behavior. For a freestanding property at global or local scope, this will be the empty tuple </span><code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;color:rgb(51,51,51)">()</code><span style="color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)">, and for a static or class property, this will be the metatype. Within the behavior declaration, the type of </span><code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;color:rgb(51,51,51)">self</code><span style="color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"> is abstract and represented by the implicit generic type parameter </span><code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;color:rgb(51,51,51)">Self</code><span style="color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)">.&quot;</span></div><div><br></div></div><div>This is somewhat strange to me.  Would it be reasonable to say that self is bound iff the behavior has a classbound requirement on Self?  Alternatively, perhaps you could somehow declare/name the declcontext type, and refer to it later by a name other than Self?</div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51)">  <span style="color:rgb(167,29,93)">mutating</span> <span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">update</span>(x: <span style="color:rgb(0,134,179)">Int</span>) {
    [foo]<span style="color:rgb(167,29,93)">.</span>x <span style="color:rgb(167,29,93)">=</span> x <span style="color:rgb(150,152,150)">// Disambiguate reference to behavior storage</span>
  }
</pre><div><br></div><div>It would be really nice to be able to keep “self” referring to the behavior, and require an explicit declaration for the enclosing declaration if a behavior requires one (e.g. in the case of atomic).</div></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><span style="background-color:rgb(255,255,255)">&quot;</span><span style="color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:1.5em;background-color:rgb(255,255,255)">Nested Types in Behaviors</span><font color="#333333" face="Helvetica Neue, Helvetica, Segoe UI, Arial, freesans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol" size="4">”</font></div><div><span style="color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:1.5em;background-color:rgb(255,255,255)"><br></span></div><div>This sounds great in the fullness of time, but it seems subsettable out of the first implementation/proposal.  Lacking this, it can be easily worked around with a private peer type.</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><pre style="overflow:auto;font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;padding:16px;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-wrap:normal;word-break:normal;color:rgb(51,51,51)">    <span style="color:rgb(150,152,150)">// Parameter gets the name &#39;bas&#39; from the accessor requirement</span>
    <span style="color:rgb(150,152,150)">// by default, as with built-in accessors today.</span>
</pre><div><span style="color:rgb(150,152,150)"><br></span></div><div><span style="color:rgb(150,152,150)"><br></span></div><div><span>Not really important for the v1 proposal, but it seems like a natural direction to allow this to be controlled by “API names” in the accessor.  The default would be that there are no API names, but if a behavior specified one, e.g.:</span></div><div><span><br></span></div><div><span style="white-space:pre-wrap">                </span>willSet(newValue newValue : Value)  </div></div><div><br></div><div>then “newValue” would be the default name in the body of the accessor.  If no “API name” were specified, then no name would be default injected.</div><div><br></div><div><br></div><div>Typographical comment w.r.t. the &quot;// Reinvent computed properties” example, you refer to the behavior as both “foobar” and “computed” later, I think the later reference is supposed to be &quot;var [foobar] bar: Int”?  Feel free to find more diversity in your metasyntactic names here :-)</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)">&quot;Accessor requirements cannot take visibility modifiers; they are always as visible as the behavior itself.&quot;</p><div>Maybe I’m misinterpreting this, but I see accessors differently.  I see them as “never being accessible to the code that declares a property using the behavior”.  If you want this, you can define a method that wraps them or something.  To a client of a behaviors, accessors are “implementation only”.</div><div><br></div><div><br></div></div><div><br></div><div><br></div><div>Can property requirements in protocols have behaviors on them?</div><div><br></div><div><br></div><br><blockquote type="cite"><div><div style="word-wrap:break-word"><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"><li>Is the problem being addressed significant enough to warrant a change to Swift?</li></ul></div></div></blockquote><div>Yep.</div><div><br></div><blockquote type="cite"><div><div style="word-wrap:break-word"><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"><li>Does this proposal fit well with the feel and direction of Swift?</li></ul></div></div></blockquote><div><div>Yep, moving generalizing special case hacks and moving them out of the compiler is a great direction.</div><div><br></div></div><blockquote type="cite"><div><div style="word-wrap:break-word"><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"><li>If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?</li></ul></div></div></blockquote><div>I have not.</div><br><blockquote type="cite"><div><div style="word-wrap:break-word"><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;Helvetica Neue&#39;,Helvetica,&#39;Segoe UI&#39;,Arial,freesans,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)"><li>How much effort did you put into your review? A glance, a quick reading, or an in-depth study?</li></ul></div></div></blockquote>I’m spent a lot of time following the discussion and chatting with Joe about this periodically, starting when Dmitri pointed out this possible direction back in Dec 2014. :-)</div><div><br></div><div>-Chris</div><br></div>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>