<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 Jun 20, 2017, at 2:25 PM, Travis Griggs &lt;<a href="mailto:travisgriggs@gmail.com" class="">travisgriggs@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Jun 20, 2017, at 7:02 AM, David Baraff via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">I posted this on Apple’s developer forums, and someone suggested trying this here.<div class="">Basically, see&nbsp;<a href="https://forums.developer.apple.com/thread/80349" class="">https://forums.developer.apple.com/thread/80349</a></div><div class=""><br class=""></div><div class="">but in a nutshell: consider that a widely used class/struct (such as CGPoint) is missing some “obvious” functionality [don’t debate that part, just go with it for now], such as the ability to scale a point by a scalar using * as an operator: so in my awesome library “GeometryBase” I write</div><div class=""><br class=""></div><div class="">&nbsp; public func * (left: CGPoint, right: double) -&gt; CGPoint {</div>&nbsp; &nbsp; &nbsp; return CGPoint(x: right*left.x, y: right*left.y)<br class="">&nbsp; }<div class=""><br class=""></div><div class="">Why public? &nbsp;Well, of course, because I want to use library GeometryBase in many apps or other libraries, and now this overload exists in only one place.</div><div class=""><br class=""></div><div class="">But other bright people have the same idea, and now I want to use their libraries. &nbsp;(some of them in my company, some of them not.)</div><div class=""><br class=""></div><div class="">And now we’re stuck, because everyone is trying to make up for the same (perceived) lack and everyone wants them public so that they don’t have to keep sticking them in each library they write.</div><div class=""><br class=""></div><div class="">This is not a made up situation: many people even within one company trying to share code somewhat informally are going to write the same code to make using CGPoint/Size/Rect easier, and now we can’t share anything safely.</div><div class=""><br class=""></div><div class="">Anybody got some good ideas what to do about this?</div><div class=""><br class=""></div><div class="">[Same question could apply to adding extensions.]</div></div></div></blockquote><br class=""></div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">I don’t have a good idea how to solve the problem. We dealt with this type of thing many years ago in Smalltalk systems.</div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Strategically, when I write application code for end user consumption, I will use my goodly sized library of base library extensions. But when I’m writing a framework to be used by other programmers, I swear off the extensions. If there is an extension that is just so essential, I’ll restrain its scope as much as possible, both with ACLs as well as obvious name prefixes:</div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>extension CGPoint {</div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>var radius_myFramework:CGFloat {</div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">                        </span>return sqrt((self.x * self.x) + (self.y * self.y))</div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>}</div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">This doesn’t do much for infix signatures though.</div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">That said, I’m glad to have this problem in Swift. I’m willing to live with the hassle it can create. The gain is worth it. I hate that Python won’t let me extend base types.</div></div></blockquote><br class=""></div><div>Also, reading about Kotlin recently, I found the exposition of extensions interesting:</div><div><br class=""></div><div><a href="https://kotlinlang.org/docs/reference/extensions.html" class="">https://kotlinlang.org/docs/reference/extensions.html</a></div><div><br class=""></div><div>In particular the part about them being resolved statically. I’ve wondered if this helps obviate this conflict problem, but I haven’t thought through it enough yet.</div><br class=""></body></html>