[swift-evolution] [Proposal] Property behaviors

Joe Groff jgroff at apple.com
Tue Dec 22 11:08:15 CST 2015

> On Dec 21, 2015, at 9:08 PM, Chris Lattner <clattner at apple.com> wrote:
>> On Dec 21, 2015, at 6:06 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>>> On Dec 21, 2015, at 5:33 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>>>> On Dec 21, 2015, at 5:21 PM, Jordan Rose <jordan_rose at apple.com> wrote:
>>>> :-( I'm worried about increasing the size of the language this much. I really want to be able to say "behaviors are just syntactic sugar for declaring accessors and storage, and then everything else behaves normally". This makes them another entirely orthogonal decl kind, like operators.
>>> I'd prefer not to have a new decl as well, if that was the best choice. However, it's still just syntactic sugar for declaring accessors and storage.
>> 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?
- 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.
- 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`.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151222/92b47300/attachment.html>

More information about the swift-evolution mailing list