<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br><br>Sent from my iPad</div><div><br>On Dec 18, 2015, at 7:05 PM, Stephen Christopher via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">+1 for this proposal. I’m not clear on the syntax and need to take some time exploring it though. <div><br></div><div>As I read the code in the proposal, it once again blurred the lines for me between property and method. It often seems to me, at an intuitive / teaching level, a property is just semantic sugar for a particular method, combined with some secret sauce to manage the backing storage for the variable. </div><div><br></div><div>Someone (Doug?) mentioned getting some documentation out that would clarify the usage of property vs. method. I’d really like to see that for comparison against my own evolving heuristics. It would also be useful in discussing this proposal.</div><div><br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi everyone. Chris stole my thunder already—yeah, I've been working on a design for allowing properties to be extended with user-defined <strike>delegates^W</strike> behaviors. Here's a draft proposal that I'd like to open up for broader discussion. Thanks for taking a look!<div><br></div><div>-Joe</div><div><br></div><div><a href="https://gist.github.com/jckarter/f3d392cf183c6b2b2ac3" target="_blank">https://gist.github.com/jckarter/f3d392cf183c6b2b2ac3</a></div><div><br></div></div></blockquote><div>… snip … </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div></div><div><div style="font-size:14px;font-family:helvetica,arial,freesans,clean,sans-serif;line-height:1.6;padding:30px;background-color:rgb(255,255,255);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;margin:15px;outline:0px;border:0px"><h1 style="margin-right:0px;margin-bottom:10px;margin-left:0px;padding:0px;font-size:28px;margin-top:0px!important"><span style="color:rgb(51,51,51);font-size:18px;font-weight:normal">Defining behavior requirements using a protocol</span><br></h1><p style="margin:0px 0px 15px">It’s reasonable to ask why the behavior interface proposed here is ad-hoc rather than modeled as a formal protocol. It’s my feeling that a protocol would be too constraining:</p><ul style="padding-left:30px"><li>Different behaviors need the flexibility to require different sets of property attributes. Some kinds of property support initializers; some kinds of property have special accessors; some kinds of property support many different configurations. Allowing overloading (and adding new functionality via <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;color:rgb(51,51,51)">extension</code>s and overloading) is important expressivity.</li><li>Different behaviors place different constraints on what containers are allowed to contain properties using the behavior, meaning that <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;color:rgb(51,51,51)">subscript</code> needs the freedom to impose different generic constraints on its <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;color:rgb(51,51,51)">varIn</code>/ <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;color:rgb(51,51,51)">letIn</code> parameter for different behaviors.</li></ul></div></div></div></blockquote><div>Would a set of related protocols (given some suppositions above that we could identify categories of behaviors that have similar needs) be another option? </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div style="font-size:14px;font-family:helvetica,arial,freesans,clean,sans-serif;line-height:1.6;padding:30px;background-color:rgb(255,255,255);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;margin:15px;outline:0px;border:0px"><p style="margin:0px 0px 15px">Instead of relying entirely on an informal protocol, we could add a new declaration to the language to declare a behavior, something like this:</p><pre style="margin-top:15px;margin-bottom:15px;background-color:rgb(248,248,248);border:1px solid rgb(204,204,204);font-size:13px;line-height:19px;overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px"><code style="margin:0px;padding:0px;border:0px;background-color:transparent;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;color:rgb(51,51,51)">behavior lazy<T> {
func lazy(...) -> Lazy { ... }
struct Lazy { var value: T; ... }
}</code></pre><h3 style="margin:20px 0px 10px;padding:0px;font-size:18px;color:rgb(51,51,51)"></h3></div></div></blockquote><div>I do like the idea of a behavior declaration. I find this to be relatively easy to model mentally. It fits with Swift’s general use of the type system to achieve both power and safety.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div style="font-size:14px;font-family:helvetica,arial,freesans,clean,sans-serif;line-height:1.6;padding:30px;background-color:rgb(255,255,255);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;margin:15px;outline:0px;border:0px"><p style="margin:0px 0px 15px">When do properties with behaviors get included in the memberwise initializer of structs or classes, if ever? Can properties with behaviors be initialized from <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;color:rgb(51,51,51)">init</code> rather than with inline initializers?</p></div></div></div></blockquote><div> 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 {` ?</div></div></div></div></div></blockquote><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Observable behaviors would not want to be precluded from initialization, but would also not want to be fired on initialization - at least that’s my first reaction. Is that true for all behaviors - that they would not want to be fired if the property is set as part of the parent type’s initialization, but only on later changes?</div></div></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAcoUhNf0ryMpki617kFxunaAFLRUfw0g-2B4uR-2F2JEQSh-2FExTvoWDe9GYEwSzo0pD7utCFVpZXrcPRw8BRpEMcS4Cc2Q0aQyxmq8-2BUw72UofKiv6pjs05nMCjlar0MZ-2BAdUqUR-2Bua1Juhb26KpJNJmzKhNna7nJuZX0FGwoj8yqJ0PD82FmHOoFvg0WKg9tvAmms-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;">
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>