<div dir="ltr"><div>Paul Cantrell wrote:<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">It seems like this fundamentally alters Swift’s aesthetic of “either an operation is type-safe, or it’s clear at the point of use that it’s not.” Should this use an operator other than a period, e.g. `pickle-&gt;loads(blob)`?<br></blockquote><div><br></div><div>This is a major concern of mine as well. What you end up by camouflaging dynamic, unchecked APIs in what looks like normal (i.e. static, checked) Swift is a wolf in sheeps’ clothing. One would not be able to tell one from the other, yet would have to juggle two completely orthogonal language models in one’s mind when reading/writing Swift code.</div><div><br></div><div>For me for such a proposal to even be remotely acceptable such dynamic calls would have to have a clearly distinguishable syntax (`foo.bar?(…)` would have been a great fit for this, but that ship has sailed).</div><div><br></div><div>In order to prevent such dynamic code from getting sprinkled all over the place (dirt gets everywhere if given enough time) I’d further more expect entire code blocks to be marked with a label that leans more towards discouragement, than encouragement, such as:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>unchecked {</div><div>    foo.bar?!(…)</div><div>}</div></blockquote><div><div><br></div><div>Brent Royal-Gordon wrote:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">* Let&#39;s step away from bridging entirely and just think about Swift for a moment. There are cases where we&#39;d like to make *semi*-dynamic proxies which wrap another type and allow operations based on what&#39;s statically known about that type. Think, for example, of the appearance proxy in UIKit: This is an object attached to UIView subclasses which lets you (in essence) set default values for all instances. We currently just pretend it&#39;s an instance of `Self`, which mostly works because of Objective-C, but a Swift-native version would probably prefer to return a `UIAppearance&lt;Self&gt;` object which used its knowledge of `Self` to expose `Self`&#39;s properties on itself. Is there a way we could design this feature, or a related feature, to cover that kind of use case? That is, to allow a limited set of keys—perhaps even key-path-based when you want static control—with a different type for each key, *or* to allow any key with some common type, depending on your type&#39;s needs?</blockquote><div><br></div><div>This particular use-case (along with NSProxy) looks to me like a perfect us of a new-type/derive as known from Haskell or Rust, rather than dynamic. (Albeit there are problems with new-type and types making use of `Self` as associated types.)</div><div><br></div><div>Doug Gregor wrote:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Swift is, unabashedly, a strong statically-typed language.</blockquote><div><br></div><div>And thankfully so, if I may say so. There a few places in the language (other than objc-bridging) where one needs to make us of dynamic features. But most of these are caused by the fact that Swift’s type system is still rather limited and certain type relations simply cannot be expressed yet, forcing one to make use of the type-safety escape hook that is Any/AnyObject.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">IMO, this proposal is a significant departure from the fundamental character of Swift, because it allows access to possibly-nonexistent members […] without any indication that the operation might fail.</blockquote><div><br></div><div>Unless there would be a corresponding compiler flag for marking use of such dynamic calls as warnings if not errors, the addition of this proposal would eliminate many of the safety guarantees that Swift gives me for code written in it for safety critical programs. If one cannot judge about the safety of a piece of code in Swift by merely looking at it, then what is the use of a remaining half-baked safety promise to begin with?</div><div><br></div><div>Matt Diephouse wrote:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">I personally don’t want to work with APIs like this. And while I can understand the appeal of easier interop—especially if you’ve come into a large library of Python code—IMO this would inevitably lead to other misuses of dynamic lookups in 1st- or popular 3rd-party libraries.</blockquote><div><br></div><div>Neither do I. The still unfinished nature of Swift’s type checking/system and lack of meta-programming capabilities will drive users of the language, who don’t know any better (especially when coming from dynamic languages), to a wide-spread misuse of such features.</div><div><br></div><div>There also is another aspect to it:</div><div><br></div><div>The main driving force behind this proposal according to this discussion is “interop with dynamic languages”.<br></div><div>The majority of language users however work in an environment where such inter is prohibited: iOS.</div><div>Releasing a feature that’s basically shouting “MISUSE ME, MISUSE ME!” at hundreds of thousands of users who’s pretty much only possible use _is_ a misuse, and of which many are coming from ObjC or Java and still at odds with, if not outright denial of Swift’s more strict type rules, is a terrible foundation, I think.</div><div><br></div><div>I also think that we should rather have a syntax sugar freeze until Swift 6 (more on that: <a href="https://blog.definiteloops.com/syntactic-diabetes-bbf54b3b4487">http://bit.ly/2BDOFxu</a>), rather than adding yet another to the mix without really thinking about the consequences (lack of coherence, e.g.).</div><div><br></div><div>Benjamin G wrote:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">A few examples of the kind of things that i would think about : <br>- use different file names for code using dynamic features.<br>- have every dynamic code included in a dynamic{} block<br>- have a different syntax for dynamic function calls, using ! or !!!<br>- Make the dynamic calls work only of subclasses of a base &quot;PythonObject&quot;. That would make the goal clear.<br>etc.<br>Now, i think those are all bad ideas (and that&#39;s why i don&#39;t like the proposal in the first place). But i really think the concern should be addressed.</blockquote><div><br></div><div>Two of these (!, !!! and dynamic {}) are similar in spirit to what I proposed above (?, ?! and unchecked {}).</div><div><br></div><div>And I too think that those are all bad ideas (and that&#39;s why i don&#39;t like the proposal in the first place).</div><div><br></div><div>Karl Wagner wrote:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">My worry is that in eagerness to try and scoop up developers of other languages, that we diminish the Swift language to the point where it doesn’t really provide a benefit for them. Python developers will be writing the same unsafe, non-checked code using Swift that they do in Python; where’s the win?</blockquote><div><br></div><div>I agree with this 100%.</div><div><br></div><div>A language should never have growth (beyond what is necessary for sustainable as a language!) be its driving force (unlike the often quoted “world dominance” of Swift). Instead a language should strive to provide the best tools for its use-case. Quality over quantity. Otherwise you’re gaining the world and losing your soul.</div><div><br></div><div>Especially when it comes to Python and JS I’m not sure I’d want their ecosystems&#39; practices to get carried over to Swift.</div><div><br></div><div>Python is infamous for its liberal use of “putting everything and the kitchen sink into stringly typed dicts”.</div><div>Please, please let’s not have this in Swift (which DynamicMemberLookup would enable all too conveniently).</div><div><br></div><div>I’m also rather skeptical about the influences of the Javascript ecosystem on Swift. The JS ecosystem is &quot;the best we could have from nothing”, but still utterly broken by design, with abominations such as leftpad being more the norm, than the exception.</div><div><br></div><div>Before opening the floodgates to external influences (from communities that dwarf the Swift community in sheer size) shall we please first wait long enough until we as a community have come to a consensus about what actually is idiomatic Swift? (Case in point: Apple claimed to have invented [sic!] Protocol-oriented Programming with Swift and touted it as the driving force behind its design. Yet a brief look at the stdlib reveals little to no use of it. It’s concrete types all over the place. Arrays all over the place.)</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">When we consider interoperability with other languages, it should be from the perspective of mapping their features to Swift’s philosophies.<br>This proposal takes the reverse approach, and makes Swift like Python, so I’m against it.</blockquote><div><br></div><div>This. I am further more of the opinion that in a pair of interoperable languages it should always be the dynamic one that’s abstracting over the static one, not the other way round. Statically typed languages are—by nature—more concrete than dynamic ones. They have to be.</div><div><br></div><div>Jon Gilbert wrote:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">However, I believe that you bring up an extremely valid concern. To extrapolate from your points, this proposal seems to have a high potential to erode what makes Swift special, and it provides a way to get around Swift’s safe-guards, avoid writing Swift versions of libraries, and ultimately, avoid hiring real Swift developers.</blockquote><div><br></div><div>This is another valid and often overlooked point. Management will find the path of least (initial) financial resistance. Every single time.</div><div>It&#39;s the very same reasons that we have more and more apps build on the technically inferior (as in much more memory &amp; power-hungry, non-native feel, etc.) Electron apps these days. And while at the current time they might look like the right solution they will be looked upon in similar ways as one looks at Flash these days. How did we manage to obsolete Flash? By extending the capabilities and expressiveness of HTML and our browsers. Let’s extend the capabilities and expressiveness of Swift, instead of dividing the ecosystem as Flash did with the web.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Why compromise Swift’s static-ness and roll out the red carpet for the dynamic, unwashed masses?</blockquote><div><br></div><div>Swift’s static-ness is the unique selling point of the language. As is for Kotlin, Rust, Haskell, and the like (all with varying degrees of static-ness). Overall we’re seeing type-systems spread through languages (in many instances in form of gradual typing). There hardly is a language out there that did not gain some kind of typing recently. Python, Ruby, Javascript, Racket, … you name it.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Everything in life and engineering is a trade-off. Swift’s trademark is that it consistently sacrifices the convenience of dynamic-ness for the safety and performance of static-ness. This proposal does seem to do the opposite, and we’d be naive not to fear the effect this will have.</blockquote><div><br></div><div>ThisI can’t help but read this proposal as a bit of a “Wait, I actually _did_ mean Swift to be Objective-C without the C, please fix!” So does this mean Craig was right after all? ;)</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Or why it would be bad for a Swift project to depend upon a stack of third-language dependencies that CocoaPods/Carthage can’t manage, XCode can’t analyze, stack traces can’t delve into (or can it?), lldb can’t step through, etc.</blockquote><div><br></div><div>This is another big one. Which is especially worrying given the state of Swift’s tooling today: there literally is none.</div><div>We have a compiler that still provides utterly unhelpful diagnostics every other day with no proper official swift-env handling, no proper cross-compilation tooling, no proper unit testing, no proper formatting, no proper lints, no proper plugins, … nothing.</div><div><br></div><div>All we have is a compiler that has much potential but is still very much unfinished. Embedded in an IDE that completely breaks down when asked to provide auto-completion and debugging support leaving a lot to be desired, too. Even in Xcode 9. Regularly. With a package manager that up until recently featured a fatal remote code execution exploit (which afaik is still there on platforms other than macOS).</div><div><br></div><div>I think we have more urgent things to work on at this point, than interop with other languages—which, as Chris pointed out don’t give a damn about Swift to begin with.</div><div><br></div></div><div>Chris Lattner wrote:</div><div><br></div><div><br></div><div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">3) Many Python APIs are wrappers for C APIs.  “Swiftizing” a Python API in this case means writing a new Swift wrapper for the API, not adding type annotations.</blockquote></div></div><div><br></div><div>Especially in the context of interoperation with machine learning / scientific computing libraries from Python I don’t get why one would want to bridge to Python.<div><br></div><div>Tensorflow, Scipy, Numpy, … they all boil down to being shallow wrappers around native language extensions written in C or C++, just as you wrote yourself.</div><div><br></div><div>What I would want is to have these be ported to/wrapped with Swift, instead of Python.</div><div><br></div><div>In general cannot see a single scenario where I would want to directly interact (as not just “please evaluate the entire file Foo.py”) with a scripting language from Swift, where it wouldn’t have been a better idea to implement either side in the given other language to begin with.</div><div><br></div><div>You want to make use of Tensorflow from Swift? Simple, use the C-API. It exists for _exactly_ this reason.</div></div><div><br></div><div>If I am coding in a low-level language to begin with, then why would I want to interface with 3rd-party languages/library on a layer that’s any higher than necessary?</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">I’m not opposed to going further over time, but I’d like to get started at some point :-).  I’m not in a super urgent hurry to get this in in the next week or month or anything like that, but I also don’t want to wait until Swift 10.</blockquote><div><br></div><div>From my point of view Swift 10 would be a perfect time to revisit the prospect of extending Swift to such dynamic use-cases. At a point where its strengths, weaknesses and idiomatic patterns have had plenty of time to be investigated.</div></div><div><br></div><div>- Vincent</div></div>