[swift-evolution] [Proposal] Property behaviors
clattner at apple.com
Tue Dec 22 12:25:32 CST 2015
On Dec 22, 2015, at 9:08 AM, Joe Groff <jgroff at apple.com> wrote:
>>> I think there’s value for users in being able to group and scope the components associated with a particular behavior, so IMO it’s worth it. Overall, it makes usage of the language less complex in practice.
>> I tend to agree. There is definite value in having really independent things scoped out and cordoned off in their own areas.
> On balance I like it too. Going with a behavior decl opens some questions though:
> - Can behaviors be extended?
From an implementation perspective, I’d prefer not. From a user model perspective (which is what really matters :) we want to be able to add methods to them somehow. I think it would be fine to require more boilerplate for this (e.g. the backing store for lazy is actually a struct, and that struct is what gets the extension) - so long as it doesn’t cause boilerplate on the client side. You shouldn’t have to say myProperty.lazy.backingStore.clear(), just myProperty.lazy.clear().
I don’t know where that leaves us :-)
> - Can behaviors be resilient? One nice thing about a fragile behavior is that we can inline its storage, if any, directly into its containing type without having to instantiate metadata for a nominal type, as we would for a struct-based property implementation. A resilient behavior, however, would end up needing more or less the same metadata to encapsulate the layout of the behavior's state behind the resilience domain, weakening that benefit.
I’d be fine with requiring an explicit struct to be defined inline in the behavior to get resilience.
> - Should behaviors be able to control their default visibility policy? As Brent and others pointed out, most behaviors are implementation details, but the few that make sense as API generally always want to be API, such as `resettable` or `KVOable`.
I’d suggest defining them to be private by default, and allowing the "var (public lazy)” sort of syntax. After the basic proposal and model is done, we can then talk about adding a “public_by_default” trait to behavior to reduce boilerplate (if it is an issue in practice).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution