<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 24 Mar 2017, at 12:13, Vladimir.S &lt;<a href="mailto:svabox@gmail.com" class="">svabox@gmail.com</a>&gt; wrote:</div><div class=""><div class=""><blockquote type="cite" class="">On 24.03.2017 12:50, Haravikk wrote:<br class=""></blockquote><blockquote type="cite" class="">I can see why some people might want to do stored properties in extensions<br class="">to structure things, but personally I quite like the lack of flexibility as<br class="">it encourages the initial type declaration to focus on what a type<br class="">*contains*, while extensions focus on what it *does*. I've really taken to<br class="">that style, as I now almost never declare methods or computed properties in<br class="">an initial type declaration, unless it's a very simple one; instead doing<br class="">all my methods and protocol conformances in their own extensions.</blockquote></div></div></blockquote><blockquote type="cite" class=""><br class=""></blockquote><blockquote type="cite" class=""><div class=""><div class="">The main problem I currently see with extensions: you can't conform to protocol in extension if you want to have stored properties to implement the protocol. And conforming to separate protocol in separate extension is a common practice and usually you need this in the same file when you define the type.<br class="">*This* was my main point when I suggest to allow stored properties *only in the same file where the type is declared*.<br class=""></div></div></blockquote><div><br class=""></div><div>Even, so I think this is kind of the right way to do it; protocols don't specify stored properties, only a name and type, so IMO it doesn't necessarily follow that fulfilling that requirement with a store property belongs in an extension.</div><div><br class=""></div><div>Consider for example a conformance to Indexable, I want to do this in an extension and I need to decide to how I'm going to handle the startIndex and endIndex properties. For some reason I decide I'll store one in my type and compute the other:</div><div><br class=""></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>struct MyCollection&lt;E&gt; {</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>let startIndex:Int = 0</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div><font face="Monaco" class=""><br class=""></font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>extension MyCollection : Indexable {</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>var lastIndex:Int { return someValue() } // it's a really bad collection</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div><br class=""></div><div>Bit contrived I know, but here I've been forced to think about where to put each, hopefully making it more obvious that my choice for startIndex was a waste of space, since it has made MyCollection 4/8 bytes larger.</div><div><br class=""></div><div>I just really like that property of the pattern; it also means that, if I keep the type declaration clean, then at a glance I can see what contributes to the type's actual contents and size. Here someone new to the code would immediately see that I was an idiot ðŸ˜‰</div><div><br class=""></div><div>I'll agree that there's some separation from the protocol that it was actually required by, but I prefer it that way to having stored properties scattered around, even within the same file (especially since we're often talking about very large files here for complex types). This "feature" is good for someone new to the code as it makes it easy to learn what is a stored vs computed property, especially if it has encouraged the developer to keep the number of stored properties to a minimum.</div><div><br class=""></div><div>I dunno, maybe it comes from having once had header files for everything, but I like this separation of concrete components of a type.</div><div><br class=""></div><div><br class=""></div><div>There was a proposal a while ago as an alternative to stored properties in regular extensions, which was the use of "mix-ins", which would be its own category. The aim of those is to modularly build up a type and quickly add conformances from reusable mix-ins, but you could also do it just for a single type.</div><div><br class=""></div><div>I preferred that idea because it formalises that this is something you can't just do to an imported type, and gets away from this idea of having something you can do with an extension, but only at the file-scope, which I feel kind of weird about.</div></div></body></html>