Skip to content
PodSubs
ShowsPeopleGuestsJobsNewsEvents
More
BlogPodCred
Menu
ShowsPeopleGuestsJobsNewsEventsBlogPodCredNetworksSign in
Join nowSign in
  • Shows
  • People
  • Jobs
  • News
  • More
    • Guests
    • Events
    • Blog
    • PodCred
    • Networks
    Join nowSign in

ADSP: Algorithms + Data Structures = Programs

ADSP: Algorithms + Data Structures = Programs artwork

Episode 183: Swift with Doug Gregor

May 24, 202428 minAudio
ShareXLinkedInFacebookWhatsAppEmail

In this episode, Conor and Bryce chat with Doug Gregor from Apple about the Swift programming language! Link to Episode 183 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Twitter ADSP: The Podcast Conor Hoekstra Bryce Adelstein Lelbach About the Guest: Douglas Gregor is is a Distinguished Engineer at Apple working on the Swift programming language, compiler, and related libraries and tools. He is code owner emeritus of the Clang compiler (part of the LLVM project), a former member of the ISO C++ committee, and a co-author on the second edition of C++ Templates: The Complete Guide. He holds a Ph.D. in computer science from Rensselaer Polytechnic Institute. Show Notes Date Recorded: 2024-04-29 Date Released: 2024-05-24 Swift Programming Language WWDC 2014 Swift Announcement Swift on Languish Intro Song Info Miss You by Sarah Jansen https://soundcloud.com/sarahjansenmusic Creative Commons - Attribution 3.0 Unported - CC BY 3.0 Free Download / Stream: http://bit.ly/l-miss-you Music promoted by Audio Library https://youtu.be/iYYxnasvfx8

Audio and video play straight from the show's own hosting. PodSubs stores and serves no media.

Transcript

From the show. Tap a time to play from there.

Craig Federighi (Clip)We have a new programming language. The language is called Swift, and it totally rolls.

ConorWelcome to ADSP The Podcast, episode 183, recorded on April 29th, 2024. My name is Connor, and today with my co-host Bryce, we interview Doug Greger. This is part four of a five-part interview, and in today's interview, we chat about the Swift programming language. I spent uh I don't know if it was a significant amount of time, but on two different occasions. One was when I was preparing for that talk, and then another time, I think I looked at it while I was covering a meetup, and I remember actually in that talk, I kind of ranked the languages that I looked at: Rust, Swift, C, D, and Haskell.

ConorAnd I think there was like three or four different metrics I ranked them based on. And one of them was just like I think it was like a happy face emoji. It was just based on like it wasn't like anything concrete, like a combination of ergonomics and how it makes you feel. And Swift won that like by a long shot. And uh one of the things that I I love about Swift, especially coming from C, is to a like remarkable extent, I could just guess like what I thought the syntax would be after you kind of got a feel for the language.

ConorAnd 90% of the time, maybe even more, you'd just be right. And it's it starts as such a simple language. And I've heard Chris Lattner, either in podcasts or in talks that he's given, talk about this idea of like infinite hackability, that it starts off feeling like Python, like a very simple, you don't need a main function, you don't need all the overhead. You know, Java's the classic example that gets picked on of the public static void main, blah, blah, blah, and you gotta include everything. And I know that Java 21 or whatever version they're on now is has simplified uh drastically simplified that hello world example, but you know uh don't apologize for Java.

BryceIt took them until version 21 to simplify that.

ConorWe love, or at least I love, all programming languages. There's something to be learned from every language, regardless of how you feel about it personally. But anyways, the point being is that Swift is it's remarkable in just how well it's designed. And the only remark that I had after that was that I tried to go and then build like a mini-game, and I was, I mean, I usually do most of my stuff on a Linux box. Now, most of these days I do WSL2 uh using Ubuntu. And at the time, I think I tried to get some panel panel library for just sort of like you know, JavaScript canvassing equivalent.

ConorAnd I at the time, and this so this was back, I want to say like 2020. So this is now four, four years ago, roughly three and a half years ago, I hit some walls pretty quickly. And most of the, and you know, I'm not a I'm not a Swifter. I'm not sure what you call folks that program in Swift a Swift E. I know that's already taken. Um, but uh most of the threads or the forms that I found basically recommended me buying uh you know an Apple machine, a laptop or something. They said they they gave you all the answers to what you wanted, but they said if you really want a pleasant experience, uh you should just go buy uh uh an Apple laptop, uh, which obviously I wasn't about to go out and do.

ConorBut I know that a long-term initiative has always been to kind of make all the experience, the Swift experience on every platform just as good as the Mac experience. So I guess my main question after once again, once again, a little mini monologue is what's the, you know, at currently Swift 5.10 and and maybe Swift 6 in the future, what's the current state of like comparison of cross-platform development? Uh you know, are we at parity with, you know, developing on a Mac machine, or what's the story for someone trying to do it on Windows or someone trying to do it on a Linux machine?

Doug GregorYeah, I think I would say we are rapidly approaching parity. So we are not exactly there. We have a very long history on Apple platforms of servicing many millions of developers. So we we've dealt with um, you know, we've made it a smooth experience there. But things have been moving very quickly to improve the experience everywhere else. And so uh if you looked in 2020, uh Linux support was there, but you could not have used it on Windows.

Doug GregorThere was no way. Right. Linux support is much more advanced. A whole lot more of the package ecosystem works on Linux as well as as Mac. Uh nowadays, there's you know editor support for VS Code and Emacs and DLVim and so on through the SourceKill SP project. Um and Windows has come along really far, really fast in the last maybe year or two. Um this has been due to the the efforts of the browser company. So this company makes a browser called Arc.

Doug GregorOkay, yeah.

ConorI think I've I think I've heard of it on one of the podcasts. There's a bunch of, you know, Opera, Brave, and I think Arc is in that kind of not Chrome, Firefox, or Safari.

Doug GregorRight, right. It's one of the other browsers. Uh so the interesting thing about it is they're in Swift, and they actually have a number of compiler developers that have been doing the hard work of making Swift work well on Windows. Interesting. And, you know, with their efforts and others from the Swift team, you know, we've managed to bring up Windows, get it up to like language parity, start getting more libraries working. Uh, there are nice installers for Windows now uh that help you get Swift up and running there. And you know, they're betting their project strategy on the ability to use Swift to write all of their code in this browser and deploy it out to various platforms.

Doug GregorSo so yeah, I think the experience isn't exactly the same, for sure, uh, but it is is rapidly getting better.

BryceThere's so many languages um go through this, and by this I mean there are many languages that get started by one shop or that that are that are founded in one place and then become community projects, and it takes a long time to truly become multi-platform, you know, community uh-owned and driven things. Rust was started by Mozilla.

BryceUm I'm sure I uh an other examples don't come to mind, but uh I'm sure Connor Google with Go, you know there we go, yeah. Yeah. Um and you know, to I think the the the length of the period in which in which the perception is this is Xorg's language is dependent upon how long it's m largely driven by that org and also by how successful it is in that that org's ecosystem.

BryceUm you know, the the fact that Swift was not just a language used internally at Apple, but it was a language that became the lingua franca on Apple's platforms, mean that that that heritage will be there for a long time. But I do imagine that as one of the Key Swift people, that it does cause some uh difficulties in trying to grow the Swift audience because there's probably a lot of people who have that assumption and bias that Swift is is Apple's language and it's only for the iOS development.

BryceAnd I I wonder what um what do you and what does the Swift team and the Swift community do to try to um uh break past that uh that perception?

Doug GregorRight. So I guess there's a couple things we do. The one is to to acknowledge that perception head on. So I gave I gave a talk back in November at a at a conference, and I I basically asked how many people here know what Swift is about, and there's a whole bunch of hands, that's fine, like what it is. I said, okay, how many of you keep your hands up, think it's Apple's language for writing iOS apps? And every basically every hand stayed up. Like that that is the perception, right? And I think you're right that it comes from its enormous success in that ecosystem.

Doug GregorSo over just a small number of years, maybe two years, two to three years out of the gate from when it was introduced, it took over the entirety of iOS app development, right? All the conferences, all the talks, the the new things coming out were all Swift focused. And so I can certainly understand.

BryceWell, why was that? Why was it so successful so quickly?

Doug GregorUm, so I think uh obviously because it's such a wonderful language. Uh sorry, I'm correct.

ConorI mean, it's true, it's true. I remember that there was a WWDC like announcement. Didn't the crowd like go go crazy? Or I don't know if you want to say crazy, but like it I remember watching a talk where it was announced, like Swift was announced, and like the audience, I don't know if it was a standing ovation, but like the reception was like amazing. Like people were thrilled to hear that they were gonna be getting, not to say anything bad about Objective-C, but they were basically gonna be getting a modern, you know, functional flavored language of the 21st century to write their apps in.

ConorAnd the demo I think that was given was was pretty amazing.

Craig Federighi (Clip)Like it was Objective-C has served us so well for 20 years. We absolutely love it. But we had to ask ourselves the question: what would it be like if we had Objective C without the baggage of C? We did more than think about it. We have a new programming language. The language is called Swift, and it totally rules.

Craig Federighi (Clip)Swift is fast, it is modern, it is designed for safety, and it enables a level of interactivity and development that you've never seen on the platform. When it comes to speed, Swift is great. Compare Python, a popular scripting language, with Objective C when it comes to something like, let's say, complex object sort. Objective C is a lot faster, but Swift is faster still. And take something like RC4 encryption, extremely comp computationally intensive.

Craig Federighi (Clip)Uh Python gets utterly crushed in this particular benchmark. And objective, but look at Swift. Now, Swift is also modern with features like closures, generics, type inference, multiple types.

ConorClassic Apple, you know, they've they've rehearsed it. It's a very, very nice introduction to this new thing that you're getting.

Doug GregorYeah, I think there's some of that. I think, you know, I I do think it is a very nice language, so you know, thank you. Um, but also I think the community was ready for it. I also think we made it really, really easy to get into. Uh, this comes back to I mentioned interoperability previously. So on day one of the Swift experience, we had file-by-file interoperability with Objective-C. So all of Apple's frameworks at the time were written in Objective-C, right? There's like hundreds of these things that come with the SDK. They were all Objective-C.

Doug GregorYou could use every single one of them very cleanly from within Swift. You could write, you could take your giant Objective-C project, this app you'd been shipping for you know years, and write one single new source file in Swift, and it would interoperate with your Objective-C cleanly. So there was no risk involved in trying it. And you don't actually see this with a whole lot of languages when they come out. Like often you have to really buy in to a whole new stack, a whole new package ecosystem to actually use the language in something.

Doug GregorWe went this far-in-grained route so that many, many people were able to try it. The great thing about that is we got a ton of feedback so we could iterate on the language, iterate on the tools, refine things to make it the language that people wanted it to be over the next couple of years. And so I I think the combination of it it being better, it being a community that is used to change and used to adopting new technologies, and also the fact that there was very little cost to trying it out meant that we were able to move people pretty quickly.

BryceAnd I mean, I I guess uh probably I guess a part of it too is being in an ecosystem with a centralized vendor that uh can can, you know, you did you didn't Swift didn't exist in a world where there were like 10 or 12 different organizations, all of whom needed to do that work to make all the frameworks interoperable. It was like that could be like a top-down decision from from Apple that, hey, we need to make this work, and and there's one org and and that that can sort of make the entire it work across the entire platform.

BryceYou try to do that in in Linux, and you gotta talk to a whole bunch of different people, all of whom have different goals and objectives, and it's a lot harder, I think, to roll out to just roll out the tools and the interop and the support that you need to.

Doug GregorI think that's largely true. Um on the other hand, we're still in a big organization. So right, and uh Swift the the interoperability that Swift enjoys with Objective-C is, or at least certainly initially, it was entirely based on the way that we designed and built the compiler. So it is a compiler feature that uh so Swift, the compiler, embeds the entire Clang compiler in it. And the way we use a C or Objective C or C library is we parse the headers.

Doug GregorAnd the compiler has a mapping from feature X in C and C and Objective C over to the way that Swift would represent that same thing. And then the code generator works along with Clang's code generator to make the API lineup.

BryceAaron Ross Powell It sounds a lot like what the Carbon project uh is is trying to get out of their interoperatory. I'm not sure how familiar you are with carbon, but it's that's the I I'm only familiar with their goals and and so on.

Doug GregorI know they've they've made interoperability with C a very first class feature in in their world and much of their strategy. Um I think they have mentioned Swift's approach um because they certainly know about us. Um Yeah.

BryceBut but it's it's interesting because I think uh very few languages um uh uh make this a priority or succeed in this uh way. And we we've talked in this podcast before about how um how hard it is uh uh for new languages to get off the ground. And I I I am a big believer in the power of inertia. Uh I like to say Bryce's rule of computing is that uh inertia is king. Um uh and you know we've talked about the this rule of thumb that you know a language has to be 10x better on some aspect to really break in.

BryceYeah. Um but that's I think less true if uh you've got a great interoperability story. And in fact, the the interoperability can be the 10x improvement that, oh wow, this is so easy for us to adopt and and and pick up and to migrate to something more modern, and we can do it incrementally. Um and that's how you get to the sort of rapid adoption that that Swifts had. I'm not sure, Connor, if you uh have graphs or data to back this up, but my understanding is that Swift is uh what when Swift was from when Swift was released to like the first couple of years, it had a very rapid growth trajectory relative to other new languages or other languages that reached the scales that it has.

BryceObviously, if you look at languages that go from like zero to a thousand users, you know, that's that's not really a uh a sample size that's sufficient to get the data. But if you're talking about going from zeros to millions of users, um I don't think there's many of the languages that have done it as quickly as Swift has.

Doug GregorI mean, I think the the language I would say is most similar in sort of rollout strategy is probably TypeScript, because it did very much the same thing there was a JavaScript ecosystem which is massive. It provided interoperability and a much better programming experience for that ecosystem and enjoyed very fast adoption.

ConorI was just gonna say there's a website, we'll we'll leave a link. I think you can hyperlink exact sort of customizations of what you select. And it's called Languish, and it's based on GitHub statistics, so you know, it's it's all of these ranking things are take them with a huge grain of salt. But if you actually look at TypeScript versus Swift from the period of like 2012, which is when this site goes back to 2016-17, TypeScript is they're they've got similar curves at first, but then something happened in 2014, and then Swift just takes off.

ConorAnd technically according to these stats, actually was higher ranked than TypeScript up until 2017. And then 2017, I think you know, TypeScript is slowly taking over the JavaScript world. But yeah, like there's this period of two, two and a half years where Swift is it's growing at this incredible rate, even even faster than TypeScript at the time. Yeah, so Swift was introduced in 2014. So Well, I have no idea what the what the data prior to 2014 is. Uh so that's it says that in 2013 Q4 and 2013 Q3, it does have some numbers, so I don't I don't know what that's from.

BryceUh so here's a possible theory. The the it it you said it's from GitHub data, right?

Doug GregorMm-hmm.

BryceYeah, so so it's possible that that the Swift project's GitHub Git history is now on GitHub. And that it's looking at looking at stuff from before it was publicly released.

Doug GregorSo that's probably the Swift compiler project's Git history goes all the way back to the the dawn of time, which obviously predates when we launched it. So that that's probably where it comes from, but you would have a small number of users at that point.

BryceSo one other thing that I think of when I think of Swift is I think of um I think of it as a uh a teaching or an education language. And even from the launch of Swift, there there has been a big focus on education, not just of like programmers, but um uh of like people who are learning to program for the first time. Uh not just of like career professional programmers who already you know know another language, but um, you know, as a first language for people. I like when I think of first languages to recommend to people, Swift's often one that's that comes to mind.

BryceWas that was that a focus from the start? Um uh you know, how did that how did that come to be?

Doug GregorSo I think it follows from one of our like philosophical points. So uh we believe very deeply in this notion of progressive disclosure. The idea that uh when you're starting out, things should be simple and straightforward. And as you grow, you start to need more capabilities. Those capabilities should be there and you can go learn about them and incorporate them. But the there's there's two sort of butts. They shouldn't, first of all, they shouldn't come to you way too early.

Doug GregorSo you shouldn't be forced to deal with a super advanced feature just because you know you step slightly outside of the bounds. Um and the other part is it shouldn't invalidate anything that you've learned so far. And so we do care a lot about the the hello world experience, right? Like you print hello world and it works, and and so that's it. Like just print and then earn quotes, hello world is fine. Um and we want it to be fairly simple to then grow into doing simple data structures and building you know your own types with structs and enums and so on.

Doug GregorAnd we do like that it can be used as a learning language. I I think it is it is valuable that people can learn a language and it can grow with them. Right? So when when they're ready, they can say, you know what? I want to learn about generic programming. It you know, Swift has a generic system. And that you know, the fun part about that is you can go and learn about generics and you write your identity functions and you learn how to write a protocol, which is basically Swift speaks for a concept. Um, and you write some generic algorithms, and then you realize that you've been using generics in your entire Swift existence because array is just a generic type defined in the library.

Doug GregorAnd you've been writing like filter and map operations on arrays as part of you know just writing code. And those are simply generic algorithms that are expressed in the library on like the collection protocol. And so it was always there, right? Like this this underlying more complex model was always there, but you weren't forced to confront it until later. And this is tricky, like. We started talking about separate type checking with generics, right?

Doug GregorYou have to have that down solid, right? Because there's nothing that kills progressive disclosure worse than something like a template instantiation backtrace, right? That just throws you into all the complexity. But you know, if if you can keep it sort of there but but not required, um you can have a language that is both complex to model all the complicated scenarios that we need when we're doing like you know full full-on software engineering, but still keep it simple and approachable enough.

BryceWell, and that there's also the the the fact that it um is so great uh uh for programming uh like GUIs and apps um and integrates so nicely with the Apple frameworks, uh I think makes it a really good teaching language, especially for like kids. And it's there's the is it called Swift Playgrounds or something like that? What's the name of the thing, the app on the right.

Doug GregorYeah, so the the Swift Playgrounds app uh lets you learn Swift on an iPad. So you know it's it's a full Swift compiler uh under the hood, but there's you know guided tutorials to help learn aspects of the language in a fun and engaging way, and then you can go off and code whatever you want.

BryceAnd I I I've I've checked it out, and it's like I think it's like like especially for like uh uh somebody under 18, like I think it's by far the best way to introduce programming to somebody. Um like I've I've tried to look at um you know, for family members, like you know, how how could you know a 13 or 14-year-old kid or even younger like learn like a programming language and like for the things that come to mind of me are like Python or Swift. And for Python, like I can go like look for things, like yeah, there's like some things out there, there's like a bunch of different like courses, but for like Swift, there's just this like this thing that's like like a a a native like first class thing that's from the the the people who make the language that you can just get on your iPad, that's great.

BryceUm, and like doesn't require a lot of setup, like you can you can do it on an iPad, which is how like young people you know access the world these days. Um and it's just like it's so it's so next level in terms of programming education. Um and uh I wonder whether there will be a long tail effect there of uh uh you know down the road there will be a lot more uh people with proficiency in Swift because they will have learned it at a younger age because it's uh uh such a good experience.

Doug GregorIt's possible. And I I would expect that people also come through the I want to build an app, what do I do? Right realm where you know we have you know, this is an Apple technology, but Swift UI is a declarative UI framework. Uh it's an interesting case because if you look at Swift UI, it's as the UI is expressed in Swift code. It's quite elegant, it's very simple, you've got you know text fields and buttons and so on. And you don't even necessarily have have to be a programmer to pick up enough to start working with it.

Doug GregorUm I know designers have have used it to be able to do essentially real code mock-ups. And it's one of those cases where I think we have succeeded at progressive disclosure because you can learn it as a first thing to do some UIs and you know, in this like sort of fun and engaging way. Now, what's behind Swift UI is a pretty amazing generic library. Uh it uses all the features of the Swift generic system, but you're not confronted with it when you're working at the at the UI layer.

Doug GregorIt's it's there if you need it. So yeah, it's it's been fun, right? We're trying to build a language for everyone. We hope that it can be your first language and we hope that it can grow with you as you do to more sort of big and complicated things.

BryceI do feel like we've sort of done you a disservice in that we didn't ask you about Swift Generics uh 30 minutes ago, and uh I I worry that we may not be able to do it justice um in the uh second hour of our recording.

ConorWhoa, whoa, what do you mean second hour? Third.

BryceUh third hour of our recording. Sorry.

ConorCounting is Bryce's weakness in this podcast, clearly. Uh I think maybe I mean, do we want to dig into it now, Connor, or should we maybe just plan to have Doug back for uh we can definitely have you back, Doug, but I I mean I would I think we should definitely I mean we can't mention you you there's no way we can leave the listener. I mean they've been we did leave the listener wanting an explanation for this, at least for a couple episodes, because Lord knows how many episodes this is gonna get cut into.

ConorThe record is five, but this could potentially become six episodes. But I'm my guess is that I'm gonna cut these maybe a little bit longer so that we don't I think our our listeners are gonna be upset if we take this whole podcast recording and then I dice it over a month and a half. I think they'll they'll just they'll end every 30-minute segment being like, come on what are we doing here? Just let it be.

BryceOh no, tell us a little bit about the Swift generics.

ConorI think I think it'll be it'll be back to back to back. Doug, dug dug dug dug for it'll either be over a month or over six weeks, but uh definitely tell us a little bit about uh the generics in Swift. But also you mentioned way back, it was probably an episode or two ago for the listener. Uh you mentioned that you know half of its lifetime has been working up to Swift 6. Be sure to check these show notes either in your podcast app or at adspthepodcast.com for links to anything we mentioned in today's episode, as well as a link to a GitHub discussion where you can leave thoughts, comments, and questions.

ConorThanks for listening. We hope you enjoyed and have a great day.

BryceLow quality, high quality, that is the tagline of our podcast.

ConorIt's not the tagline. Our tagline is chaos with sprinkles of information.

Open the transcript file

Hosts and Guests

Guests

  • Doug Gregor Guest Inferred
  • Douglas Gregor Guest Inferred

Credit the people on this episode

Be the first to rate this episode

More episodes

All episodes
  1. Episode 313: C++26 Reflection vs CRTP, AI, Kids & More with Zach Laine

    Nov 20, 202647 minAudio

    In this episode, Conor and Bryce chat with Zach Laine about C++26 Reflection vs CRTP, AI, kids & more. Link to Episode 313 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials ADSP:...

    • Apple Podcasts

    Credit the people on this episode

  2. Episode 312: The C++26 Contracts Fiasco

    Nov 13, 202652 minAudio

    In this episode, Conor and Bryce chat with Zach Laine about the C++26 contracts fiasco. Link to Episode 312 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials ADSP: The Podcast:...

    • Apple Podcasts

    Credit the people on this episode

  3. Episode 311: Career Changes, GPUs & More with Zach Laine

    Nov 6, 202628 minAudio

    In this episode, Conor and Bryce talk with Zach Laine about his career and the career changes he has made. Link to Episode 311 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials...

    • Apple Podcasts

    Credit the people on this episode

  4. Episode 310: Leaving NVIDIA for... ?

    Oct 30, 202624 minAudio

    In this episode, Conor and Bryce talk about Bryce's next chapter and where he is leaving NVIDIA for. Link to Episode 310 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials ADSP: The...

    • Apple Podcasts

    Credit the people on this episode

  5. Episode 309: Default Construction & CppCon 2026 with Jason Turner

    Oct 23, 202629 minAudio

    In this episode, Conor and Ben chat with Jason Turner about default construction in C++. Link to Episode 309 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials ADSP: The Podcast:...

    • Apple Podcasts

    Credit the people on this episode