[swift-evolution] [Proposal] Property behaviors

Stephen Christopher schristopher at bignerdranch.com
Fri Dec 18 20:11:30 CST 2015


>
>
> 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.

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151218/8e5aab05/attachment.html>


More information about the swift-evolution mailing list