[swift-evolution] [Proposal] Property behaviors
Joe Groff
jgroff at apple.com
Fri Jan 22 18:33:35 CST 2016
I've revised my proposal again based on more feedback. Syntax changes include:
- adopting John McCall's declaration-follows-use syntax for behavior declarations. I think this looks nice and provides a reasonable framework for binding all the fiddly bits of a property, such as its type, name, and initializer.
- changing the proposed syntax for behavior member lookup to 'property.[behavior].member', as suggested by Tal Atlas and others. I think this has a nice symmetry with the `var [behavior]` declaration syntax, and doesn't occupy any new sigils. On the other had, Curt Clifton and others have raised the point that it could be mistaken for a subscript at a glance.
To reduce the complexity of the initial feature review, I've also removed many of the bells and whistles from this initial version for separate consideration. For now, I'm saying initializer requirements are always "eager" (can't refer to self) and always inline-initialized. This imposes some inconvenience on some use cases, but is an additive feature. I've also left behavior composition, extending behaviors, overloading behaviors, and name binding as future extensions. Joe Pamer raised some design and technical challenges around how type inference should work with behaviors too, which I think deserve focused discussion, so I'm sidestepping those issues by starting out saying properties with behaviors always need an explicit type. Here's the updated proposal:
https://gist.github.com/jckarter/66ae8fb361c0d57b3227
And for reference, previous iterations:
https://gist.github.com/jckarter/50b838e7f036fe85eaa3
https://gist.github.com/jckarter/f3d392cf183c6b2b2ac3
-Joe
More information about the swift-evolution
mailing list