[swift-evolution] [Proposal] Property behaviors

Matthew Johnson matthew at anandabits.com
Fri Dec 18 20:23:13 CST 2015



Sent from my iPad

On Dec 18, 2015, at 8:11 PM, Stephen Christopher <schristopher at bignerdranch.com> wrote:

>> 
>>>> When do properties with behaviors get included in the memberwise initializer of structs or classes, if ever? Can properties with behaviors be initialized from init rather than with inline initializers?
>>>> 
>>>  There’s a separate discussion that mentioned allowing better control of which initializers are generated or synthesized for a given struct. There’s also been mention of a “derived” feature for adding conformance without needing to supply a separate implementation. This question seems related to me - it would be ideal if Swift had a coherent way to declare something that did not need definition because it can be generated by the compiler. In this case, to declare that a property is part of memberwise initialization. `behavior lazy<T>: memberwise {` ?
>> 
>> You might be talking about the initialization discussion I was involved in a week or so ago.  I'm working on a proposal that would allow for more flexible control over synthesized memberwise initialization.  I'm hoping to have a draft ready soon.
> 
> Great! Looking forward to reading it.
>  
>> 
>> Is your example here part of a behavior declaration for lazy which states that properties with the lazy behavior may be memberwise initialized?  That's what it looks like to me.  I think syntax like that would make sense.  There are some behaviors which would need to opt out.  Somewhat ironically, I think lazy is one of them as the whole point of it is that it is not initialized immediately, but rather on first access.
> Yes, that was the idea behind that syntax. Hah, lazy was a terrible example, you’re right. Distracted emailing never ends well.

I've had a couple incidences of distracted emailing on the list myself!  I hope to learn from those mistakes and not repeat it again. :)

> 
> It could be either opt-in (as my example hinted). Opt-out might be a bit harder to express, and I’m not sure if opt-in is the right default. 

I think opt-in is the right default for behaviors as it conflicts with the semantics of some behaviors.

I don't think a property with a behavior that *allows* memberwise initialization should be required to support it just because the behavior does.  Part of my proposal discusses properties which cannot be memberwise initialized because of access control restrictions or because they have an @nomemberwise attribute.  This might not make a lot of sense without seeing it in the context of the proposal, but it should once I have the draft ready to share.

Matthew

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


More information about the swift-evolution mailing list