<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="">Because to me this seems too indirect and not explicit enough.<div class=""><br class=""><div class="">I think doing it explicitly:</div><div class="">• Makes your intent much clearer</div><div class="">• Forces you to think about not throwing everything into one big extension (i.e. somewhat more binding than a comment that can easily be looked over)</div><div class="">• Shows that it’s a first class feature of the language, encouraging everyone to use it. Makes it easier to see in tutorials and code samples as it reads more natural than // MARK:</div><div class="">• Does not feel hacky with a comment (and comments are easy to forget to update, making them possibly outdated)</div><div class="">• Looks better than having to use comments (imo)</div><div class=""><br class=""></div><div class="">It is reminiscent of named categories in Objective-C where I found the names to be quite self documenting and clearer.</div><div class=""><br class=""></div><div class="">To me it just feels like a natural extension…onto extensions.</div><div class=""><br class=""></div><div class="">In the end, there is nothing with wrong using comments, but it feels a little more archaic to me. </div><div class=""><br class=""></div><div class="">For a little contrived example:</div><div class=""><br class=""></div><div class="">In the swift guide, there is an example like this:</div><div class=""><br class=""></div><div class=""><ol class="code-lines" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; counter-reset: li 0; line-height: 1.6em; list-style: none; font-family: Helvetica, Arial, sans-serif;"><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"><span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">extension</span> <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> {</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">km</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> * <span class="m" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(28, 0, 207);">1_000.0</span> }</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">m</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> }</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">cm</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> / <span class="m" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(28, 0, 207);">100.0</span> }</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">mm</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> / <span class="m" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(28, 0, 207);">1_000.0</span> }</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">ft</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> / <span class="m" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(28, 0, 207);">3.28084</span> }</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;">}</code></li></ol><div class=""><font face="Helvetica, Arial, sans-serif" class=""><br class=""></font></div><div class=""><font face="Helvetica, Arial, sans-serif" class="">• It is clear what the intent is here: to provide methods to convert a double into other units</font></div><div class=""><font face="Helvetica, Arial, sans-serif" class="">• Why not make this intent explicit? Otherwise it is too easy to add unrelated methods:</font></div><div class=""><font face="Helvetica, Arial, sans-serif" class=""><br class=""></font></div><div class=""><ol class="code-lines" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; counter-reset: li 0; line-height: 1.6em; list-style: none; font-family: Helvetica, Arial, sans-serif;"><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"><span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">extension</span> <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> {</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">km</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> * <span class="m" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(28, 0, 207);">1_000.0</span> }</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">m</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> }</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">cm</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> / <span class="m" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(28, 0, 207);">100.0</span> }</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">mm</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> / <span class="m" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(28, 0, 207);">1_000.0</span> }</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">ft</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> / <span class="m" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(28, 0, 207);">3.28084</span> }</code></li></ol><div style="text-indent: -13px;" class=""><br class=""></div><div style="text-indent: -13px;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> <span class="kt" style="font-family: Menlo, monospace; font-size: 11.899999618530273px; white-space: pre-wrap; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span><span style="font-family: Menlo, monospace; font-size: 12px; white-space: pre-wrap;" class=""> </span><span class="vc" style="font-family: Menlo, monospace; font-size: 11.899999618530273px; white-space: pre-wrap; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">squared</span><span style="font-family: Menlo, monospace; font-size: 12px; white-space: pre-wrap;" class="">: </span><span class="n" style="font-family: Menlo, monospace; font-size: 11.899999618530273px; white-space: pre-wrap; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span><span style="font-family: Menlo, monospace; font-size: 12px; white-space: pre-wrap;" class=""> { </span><span class="kt" style="font-family: Menlo, monospace; font-size: 11.899999618530273px; white-space: pre-wrap; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span><span style="font-family: Menlo, monospace; font-size: 12px; white-space: pre-wrap;" class=""> </span><span class="kt" style="font-family: Menlo, monospace; font-size: 11.899999618530273px; white-space: pre-wrap; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self * self</span><span style="font-family: Menlo, monospace; font-size: 12px; white-space: pre-wrap;" class=""> } //This computed property is unlike the others, introducing some bloat to this extension</span></div><ol class="code-lines" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; counter-reset: li 0; line-height: 1.6em; list-style: none;"><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;">}</code></li></ol><div class=""><br class=""></div></div><div class=""><font face="Helvetica, Arial, sans-serif" class=""><br class=""></font></div><div class=""><font face="Helvetica, Arial, sans-serif" class=""><br class=""></font></div><div class=""><font face="Helvetica, Arial, sans-serif" class="">Something like this is more “explicit”</font></div><div class=""><font face="Helvetica, Arial, sans-serif" class=""><br class=""></font></div><div class=""><ol class="code-lines" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; counter-reset: li 0; line-height: 1.6em; list-style: none; font-family: Helvetica, Arial, sans-serif;"><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"><span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);"><font color="#4f8187" class="" style="font-family: Menlo; text-indent: 0px; white-space: normal;"> </font><font color="#bb2ca2" class="" style="font-family: Menlo; text-indent: 0px; white-space: normal;">named </font><font color="#d12f1b" class="" style="font-family: Menlo; text-indent: 0px; white-space: normal;">Unit Conversion </font>extension</span> <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> {</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">km</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> * <span class="m" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(28, 0, 207);">1_000.0</span> }</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">m</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> }</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">cm</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> / <span class="m" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(28, 0, 207);">100.0</span> }</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">mm</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> / <span class="m" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(28, 0, 207);">1_000.0</span> }</code></li><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; white-space: pre-wrap; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; font-size: 0.85em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; font-family: Menlo, monospace; word-wrap: break-word;"> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">var</span> <span class="vc" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(63, 110, 116);">ft</span>: <span class="n" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double</span> { <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">return</span> <span class="kt" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">self</span> / <span class="m" style="border: 0px; font-size: 11.899999618530273px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(28, 0, 207);">3.28084</span> }</code></li></ol><div style="text-indent: -13px;" class=""><br class=""></div><div style="text-indent: -13px;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> <span style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 12px;" class="">//var squared: Double { return self * self } It is not clear that this method does not fit with the others and should be moved</span></div><ol class="code-lines" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; counter-reset: li 0; line-height: 1.6em; list-style: none;"><li style="border-width: 0px 0px 0px 18px; border-left-style: solid; border-left-color: transparent; margin: 0px; outline: 0px; padding: 0px 10px 0px 0px; vertical-align: baseline; text-indent: -13px; list-style-type: none;" class=""><code class="code-voice" style="border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;">}</code></li></ol><div class=""><br class=""></div></div><div class="">There is somewhat of a contract here where everything in this extension is a kind of conversion. Anyone could still add whatever they want to this extension because this is really just a form of documentation and it has no idea whether what you are adding fits with the name, but I find it to be a little more binding and requires the programmer to ask themselves if their addition fits with the rest of the extension.</div><div class=""><br class=""></div><div class=""><b class="">The obvious question again is: Why not just use a comment to document it?</b> My answer to this is: I don’t think most use comments to signify their intent of the extension. They either do not know it exists or do not find it worthwhile. I think making it explicit to the language gives people incentive to use it. It would be included in more code samples because it is a natural part of the extension and not “just another comment” to skim by, meaning more people would know it exists and use it more.</div><div class=""><br class=""></div><div class="">Also, no <span style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 12px;" class="">// MARK: Bar </span>syntax needs to be remembered. MARK: is also less pretty and harder to type</div><div class=""><br class=""></div><div class="">More formatting options:</div><div class=""><br class=""></div><div class=""><span class="kt" style="font-family: Menlo, monospace; font-size: 11.899999618530273px; text-indent: -13px; white-space: pre-wrap; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);"><font color="#bb2ca2" class="" style="font-family: Menlo; text-indent: 0px; white-space: normal;">named </font><font color="#d12f1b" class="" style="font-family: Menlo; text-indent: 0px; white-space: normal;">Unit Conversion </font></span></div><div class=""><span class="kt" style="font-family: Menlo, monospace; font-size: 11.899999618530273px; text-indent: -13px; white-space: pre-wrap; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">extension</span><span style="font-family: Menlo, monospace; font-size: 12px; text-indent: -13px; white-space: pre-wrap;" class=""> </span><span class="n" style="font-family: Menlo, monospace; font-size: 11.899999618530273px; text-indent: -13px; white-space: pre-wrap; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double {</span></div><div class=""><span class="n" style="font-family: Menlo, monospace; font-size: 11.899999618530273px; text-indent: -13px; white-space: pre-wrap; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">}</span></div><div class=""><div class=""><br class=""></div></div><div class=""><span class="kt" style="font-family: Menlo, monospace; font-size: 11.899999618530273px; text-indent: -13px; white-space: pre-wrap; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(170, 51, 145);">extension</span><span style="font-family: Menlo, monospace; font-size: 12px; text-indent: -13px; white-space: pre-wrap;" class=""> </span><span class="n" style="font-family: Menlo, monospace; font-size: 11.899999618530273px; text-indent: -13px; white-space: pre-wrap; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: rgb(92, 38, 153);">Double, </span><font color="#bb2ca2" class="" style="font-size: 12px; font-family: Menlo;">named </font><font color="#d12f1b" class="" style="font-size: 12px; font-family: Menlo;">Unit Conversion </font><span style="text-indent: -13px;" class=""><font color="#5c2699" face="Menlo, monospace" class=""><span style="font-size: 12px; white-space: pre-wrap;" class="">{ //avoids requiring “ "</span></font></span></div><div class=""><span style="color: rgb(92, 38, 153); font-family: Menlo, monospace; font-size: 12px; text-indent: -13px; white-space: pre-wrap;" class="">}</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 12px;" class=""> </span></div><div class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 12px;" class=""><br class=""></span></div><div class="">At the end of the day, how many developers know and remember to use // MARK:? I think this feature with code completion would promote much wider adoption.</div><div class=""><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 12px;" class=""><br class=""></span></div><div class="">Brandon</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 16, 2016, at 1:33 PM, Michael Peternell <<a href="mailto:michael.peternell@gmx.at" class="">michael.peternell@gmx.at</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Why not just use a (documentation) comment?<br class=""><br class="">/// The Lifecycle extension:<br class="">extension ViewController {<br class="">...<br class=""><br class="">-Michael<br class=""><br class=""><blockquote type="cite" class="">Am 16.05.2016 um 18:26 schrieb Brandon Knope via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>:<br class=""><br class="">I like to separate methods into their own logical extensions so similar methods are grouped together. I do this mostly with Cocoa Touch where I like all view life cycle methods to be in the same extension:<br class=""><br class="">extension ViewController {<br class=""> override func viewDidLoad() {<br class=""> }<br class=""><br class=""> override func viewWillAppear(animated: Bool) {<br class=""> }<br class=""><br class=""> override func viewDidDisappear(animated: Bool) {<br class=""> }<br class="">}<br class=""><br class="">You can document this somewhat by adding a MARK comment:<br class=""><br class="">// MARK: Lifecylce<br class="">extension ViewController {<br class=""> override func viewDidLoad() {<br class=""> }<br class=""><br class=""> override func viewWillAppear(animated: Bool) {<br class=""> }<br class=""><br class=""> override func viewDidDisappear(animated: Bool) {<br class=""> }<br class="">}<br class=""><br class="">What if we made this more self-documenting by elevating this to a language feature?<br class=""><br class="">extension ViewController named Lifecycle {<br class=""> override func viewDidLoad() {<br class=""> }<br class=""><br class=""> override func viewWillAppear(animated: Bool) {<br class=""> }<br class=""><br class=""> override func viewDidDisappear(animated: Bool) {<br class=""> }<br class="">}<br class=""><br class="">Other ways:<br class="">extension named Lifecycle ViewController { }<br class="">extension named “View Lifecycle" ViewController { }<br class="">extension ViewController named “Multi word description” { }<br class=""><br class=""><br class="">For now, this is purely a documenting feature (i.e. Can’t refer to the extension name dynamically or statically in actual code). I think it plays much more naturally with Swift than requiring this to be in the comments and would work across all IDEs and make it easier for people to find a specific extension as well as making their code more self documenting.<br class=""><br class="">Any thoughts?<br class=""><br class="">Thanks,<br class="">Brandon<br class=""><br class=""><br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></div></div></div></body></html>