[swift-evolution] Proposal: Universal dynamic dispatch for method calls

Chris Lattner clattner at apple.com
Mon Dec 14 00:03:21 CST 2015


On Dec 13, 2015, at 9:34 PM, Paul Cantrell <cantrell at pobox.com> wrote:
> I realize I’m straying for the topic of the thread (and Brent’s neglected proposal, which I really do mean to think some more about), but how I can I not chime in to these wonderful musings on language design?

No problem, I’m taking time to pontificate here for the benefit of the community, hopefully it will pay itself back over time, because people understand the rationale / thought process that led to Swift better :-)

>>> When you say “programmer model,” I understand you to mean "how a Swift programmer thinks about the language’s semantics while writing Swift code, without regard to how they’re implemented in the compiler.”
>> 
>> Yes.  Except in extreme cases, the interesting question isn’t whether it is “possible" to do thing X in language Foo, it is to ask whether Foo “encourages" X and how it rewards it.
> 
> Yes! When students ask why they should take Theory of Computation, part of my answer is that it’s good to get a really deep handle on the question of what’s possible in a language, and how very different that is from the question of what’s elegant in a language. The Church-Turing Thesis closes the door on a whole category of questions about what a given language can do: algorithmically, all these languages we work with are equivalent! 

Yep, almost.  I’m still hoping to get an infinite tape someday :-)


> Thanks for this. I was thinking “programmer model” meant only the programmer’s mental model of the language — but you’re talking about something broader and deeper: the style, the culture, the patterns of thought, and the aesthetics that arise from the experience of working with a particular language.

Right.

> So … how do you test this?

You can only test it by looking at a large enough body of code and seeing what problems they face.  Any language that is used widely will evidence of problems that people are having.  There are are shallow problems like “I have to type a few extra characters that are redundant and it annoys me”, and large problems “Two years into my project, I decided to throw it away and rewrite it because it had terrible performance / didn’t scale / was too buggy / couldn’t be maintained / etc".   I don’t believe that there is ever a metric of “ultimate success", but the more big problems people have, the more work there is left to be done.

The good news is that we, as programmers, are a strongly opinionated group and if something irritates us we complain about it :-).  It is somewhat funny that (through selection bias) I have one of the largest list of gripes about Swift, because I see a pretty broad range of what people are doing and what isn’t working well (a result of reading almost everything written about swift, as well as tracking many, many, bug reports and feature requests).  This drives my personal priorities, and explains why I obsess about weird little things like getting implicit conversions for optionals right, how the IUO model works, and making sure the core type checker can be fixed, but prefer to push off “simple” syntactic sugar for later when other pieces come in.

> How do you evaluate language features for it? I think of these questions about protocol extensions, and trying to predict the resulting programmer model seems a fool’s errand.

Adding a feature can produce surprising outcomes.  A classic historical example is when the C++ added templates to the language without realizing they were a turing complete meta-language.  Sometime later this was discovered and a new field of template metaprogramming came into being.  Today, there are differing opinions about whether this was a good or bad thing for the C++ programmer model.

That said, most features have pretty predictable effects, because most features are highly precedented in other systems, and we can see their results and the emergent issues with them.  Learning from history is extremely important.  You can also think about the feature in terms of common metrics by asking things like “what is the error of omission?” which occurs someone fails to think about the feature.  For example, if methods defaulted to final, then the error of omission would be that someone didn’t think about overridability, and then discovered later that they actually wanted it.  If symbols defaulted to public, then people would naturally export way too much stuff, because they wouldn’t think about marking them internal, etc.

>> Swift doesn’t achieve this by being “watered down” for newbies, it does this by factoring the language so that power-user features can be learned at the appropriate point on the learning curve.  “Niche”  features for power uses make sense when they enable new things things being expressed, new markets to be addressed, or new performance wins to be had.  This is key to Swift being able to scale from “low level system programming” all the way up to “scripting”, something I’m quite serious about.
> 
> The other half of this is that the language doesn’t impose any cognitive burden on those who don’t use the niche / expert features. I don’t want to be an expert in everything all the time; I want to be able to focus on only the tools appropriate to the problem at hand. I don’t want to have to worry about bumping into the unshielded circular saw every time I pick up a screwdriver, even if I do know how to use a circular saw.
> 
> I like what Swift has done on this front so far. UnsafePointer is a great example. Swift can still provide bare memory access without making it ubiquitous. Take that, C++!

Right!

> On which note: is there thought of eventually bootstrapping the Swift compiler?

There are no short term plans.  Unless you’d consider rewriting all of LLVM as part of the project (something that would be awesome, but that I wouldn’t recommend :-), we’d need Swift to be able to import C++ APIs.  I’m personally hopeful that we’ll be able to tackle at least some of that in Swift 4, but we’ll see - no planning can be done for Swift 4 until Swift 3 starts to wind down.

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151213/1b5ceae1/attachment.html>


More information about the swift-evolution mailing list