<div dir="ltr">I don&#39;t mean stored properties declared in extensions. I&#39;m talking about conforming to a &quot;mixin&quot; protocol via an extension in another file. For example:<div><br></div><div>// Foo.swift</div><div>struct Blah {</div><div>    var x : Int</div><div>}</div><div><br></div><div>// Mixins.swift</div><div>protocol MyMixin {</div><div>    var y : Double // mixin having a stored property</div><div>}</div><div><br></div><div>// Bar.swift</div><div>extension Blah : MyMixin {} // this changes the size of all instances of Blah in the program</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Feb 27, 2016 at 11:26 AM, Антон Жилин <span dir="ltr">&lt;<a href="mailto:antonyzhilin@gmail.com" target="_blank">antonyzhilin@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">In my current proposal, stored properties of protocols have no abilities beyond that of structs. They cannot be declared in extensions, that&#39;s intentional. Could you give an example where such decoupled definition would be better than multiple mixins, for example?</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2016-02-27 19:17 GMT+03:00 Trent Nadeau <span dir="ltr">&lt;<a href="mailto:tanadeau@gmail.com" target="_blank">tanadeau@gmail.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">One limitation for &quot;mixin&quot; protocols would be that they can&#39;t be retroactively modeled, e.g. by having an extension for that protocol on a type outside of its file of definition. Allowing this would make the size of structs and classes unknowable to the compiler as an extension in another library could change the size of all instances.<div><br></div><div>That limitation is restrictive enough that having a special type of protocol and an associated keyword (&quot;mixin&quot;) would probably be beneficial. The compiler could then easily check the intent of the protocol and ensure that a library doesn&#39;t break existing extensions just by adding a stored property. Only mixin protocols would have this capability. </div></div><div class="gmail_extra"><div><div><br><div class="gmail_quote">On Sat, Feb 27, 2016 at 9:00 AM, Radosław Pietruszewski <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><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>This is compelling to me.</div><div><br></div><div>I haven’t put enough thought into it to make up my mind about it, but a mixin system would solve a problem I’m currently struggling with.</div><div><br></div><div>I’ve been working on cleaning up the codebase of my iOS/Mac app, and I’m trying to reduce duplication between the codebases. The problem is, there are things that aren’t easy to completely encapsulate into a separate, universal class — things that have bits and pieces in common, but different overall shape.</div><div><br></div><div>Perhaps I should encapsulate them anyway, add a level of indirection, inject dependencies… But a mixin is an abstraction that would allow me to extract common parts in an easier way.</div><br><div>
<div>— Radek</div>
</div>
<br><div><blockquote type="cite"><div><div><div>On 27 Feb 2016, at 10:59, Антон Жилин via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br></div></div><div><div><div><div dir="ltr">Some people opposed to Abstract Classes proposal (including myself) have said that mixins could solve the problem better.<div>So I prepaired a proposal draft to add stored properties to protocols. Here it is:</div><div><a href="https://gist.github.com/Anton3/f0550922c1be0fc5447c" target="_blank">https://gist.github.com/Anton3/f0550922c1be0fc5447c</a><br></div><div><br></div><div>P.S. I added a `mixin` keyword in the beginning, but we can opt to just extend protocols, which I mention in &quot;alternatives&quot;.</div></div></div></div><span>
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></span></div></blockquote></div><br></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div></div></div><span><font color="#888888">-- <br><div>Trent Nadeau</div>
</font></span></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Trent Nadeau</div>
</div>