[swift-evolution] [Proposal] Property behaviors

Jordan Rose jordan_rose at apple.com
Mon Jan 25 22:15:38 CST 2016


> On Jan 25, 2016, at 18:54 , Joe Groff <jgroff at apple.com> wrote:
> 
> 
>> On Jan 25, 2016, at 6:40 PM, Jordan Rose <jordan_rose at apple.com <mailto:jordan_rose at apple.com>> wrote:
>> 
>> Finally caught up. :-) I like this latest version better than the two previous versions, but I kind of think that if behaviors can't emulate "lazy", we've failed. Nothing has a stronger motivation than that at this point in time; there's lots of cool things we could use behaviors for, but you can still write all of them with a wrapper type.
> 
> Not sure what you mean. It can.

But you have this in your other message:

> For now, I'm saying initializer requirements are always "eager" (can't refer to self) and always inline-initialized.

Is it really just "can't refer to self" and not actually "eager"?


>> - Someone else brought this up, but can I override behavior methods in a subclass with a new behavior? Can I invoke super's implementation of those behavior methods?
>> 
>> - Can I wrap a superclass property with a behavior? This version of the proposal doesn't have 'base', so I assume the answer is no, but that knocks out the other special-case language feature that was to be replaced by the general feature.
> 
> We're not done yet; this is just version 1. I'm subsetting composition out, since that's also an interesting discussion unto itself. You ultimately ought to be able to wrap a superclass property in new behaviors, but I don't see how you could replace a behavior without violating the superclass's encapsulation. Chaining to super behavior members also feels a bit overly intimate; do you have a use case in mind?

willSet or didSet wrapping a superclass setter is not at all uncommon, and the sort of things you wrap with didSet are usually things that want to know about reset() as well. I'm not sure any of your other examples of property methods have this problem, though—it might only be things that are set-like.

Jordan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160125/7389de52/attachment.html>


More information about the swift-evolution mailing list