[swift-evolution] [Review] SE-0030 Property Behaviors

Ricardo Parada rparada at mac.com
Fri Feb 19 14:55:21 CST 2016


Hi Joe,

Why would we want to move the initialValue declaration into the body?  I personally like it outside because it mirrors the declaration of the actual property.  

Also, I know the current proposal does not have a binding to get a hold of the property name.  But let’s suppose that we wanted to add one as in the behavior declaration below.  Notice that the right hand side of the behavior declaration (in bold) mirrors the property name, the value type and initial value respectively of a var declaration.  Based on this, I find it intuitive to make the connection and understand what name, Value and initialValue are referring to.  No need to have special declarations in the body of the behavior.  

At some point you had provided an “echo” property that showed the use of the name binding to get a hold of the property name.  Then in subsequent proposals you had an _ for the place of the property name in the behavior declaration.  Now I see that it’s been completely dropped.  I personally liked it and think it could be useful.  I probably missed in past discussions the reason why the binding for the property name was dropped.  Do you see it coming back, perhaps in a separate proposal?

As far as @lazy, etc. to annotate var declarations and have them use property behaviors, I cannot think of any reasons why not. It could also be @behavior(lazy) but it seems more verbose.

public var behavior changeObserved<Value: Equatable> name: Value = initialValue {

  var value = initialValue

  mutating accessor didChange(oldValue: Value) { }

  get {
    return value
  }
  set {
    let oldValue = value
    value = newValue
    if oldValue != newValue {
      didChange(oldValue)
    }
  }
}

Thank you
Ricardo Parada



> On Feb 19, 2016, at 1:36 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Feb 18, 2016, at 10:09 PM, Thorsten Seitz <tseitz42 at icloud.com <mailto:tseitz42 at icloud.com>> wrote:
>> 
>> This might be an editing problem with th examples. In the Proposed Solution the syntax is
>> 
>> public var behavior lazy<Value> = initialValue { ... }
>> 
>> which makes sense to me (though it is missing the type declaration (: Value) here.
> 
> That was a botched update on my part; I did intend to move the initialValue requirement declaration into the body:
> 
> public var behavior lazy<Value>:Value { initialValue; ... }
> 
> -Joe
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160219/6ebe90a2/attachment.html>


More information about the swift-evolution mailing list