The Stack Overflow Podcast

Spreading the gospel of Python

Episode Summary

On this episode: Al Sweigart is a software developer, developer advocate, and author of ten Python books. He tells Ben and Ryan why he’s such a fan of the language, why it’s a great programming language for beginners, and how it became the default for so many data science and backend AI projects.

Episode Notes

Al Sweigert is the author of Automate the Boring Stuff with Python and many other books about programming. You can read them all for free here.

His scroll art project introduces beginners to programming by letting them turn loops and print() into animated ASCII art.

Al joined us from a retreat at the Brooklyn, NY-based Recurse Center, which offers free, self-directed retreats for programmers. Learn how to apply here.

PyCon US 2024 is May 15-23, 2024, in Pittsburgh, Pennsylvania.

Connect with Al through his website.

Shoutout to user Alex. S., who asked Stack Overflow’s most popular Python question ever: What does the "yield" keyword do in Python?. It’s helped 3.3 million people and counting.

Episode Transcription

[intro music plays]

Ben Popper Hello, everybody. Welcome back to the Stack Overflow Podcast, a place to talk all things software and technology. I am Ben Popper, Director of Content here at Stack Overflow, joined by my colleague and co-host, Ryan Donovan. Ryan, you suggested today's guest, so why don't you do a little warm up for the audience? Who are we talking to and what are we going to chat about? 

Ryan Donovan So our guest today is Al Sweigart. He's written a bunch of books on Python, including, Automate the Boring Stuff, about Python for regular people, but also has a ton of books on Python and is a big Python advocate so I figured we can see why Python is such a focus for him.

BP Terrific. Al, welcome to the Stack Overflow Podcast. You're coming to us from something kind of unique, let's start there. You're on a retreat.

Al Sweigart Hello! Thanks for having me. So currently I'm in Brooklyn attending The Recurse Center, which is sort of an artist retreat but for software developers. The Recurse Center has these 12-week programs or 6-week programs where you basically just come and work on a project of your choosing surrounded by other people who are also working on their own projects. And it's just a great place to be around other software developers who are constantly trying to improve their craft who are working on interesting projects, and it has been life-changing. I think a really common thing among Recursers is that they will inevitably start talking about The Recurse Center over and over and over again with everyone. So I encourage people to check it out. It's The Recurse Center, it's recurse.com. It's a free program, but if you want to attend in person, you have to be in New York, so it's kind of expensive in that sense. But they also have remote options as well and you can just find out about them online at recurse.com. 

RD Very cool. 

BP Are you working on something that's at the intersection of art and software while you're there? Or what is the project you're finding yourself getting into? 

AS Well, I had this one grand idea for a board game web app that I was working on, but I quickly got sidetracked by a bunch of other things and I started developing something I call ‘scroll art,’ which is sort of like ASCII art, but if you imagine if you were of a certain age, you probably got started with programming writing that Basic program, 10 print Hello; 20 GOTO 10. And so this would just be an infinite loop and fill up the screen with ‘Hello’ and eventually it would start scrolling all the text upwards. And I thought, “Well, that's really interesting. It's a kind of animation there.” So essentially scroll art is just programs that have print function calls inside of a loop and you can then use that to generate a sort of upward flowing and scrolling animation. I have a lot of examples at scrollart.org, which is a website that I finally had time to put together. And what I really like about this is that it's a form of animation but you don't have to install any graphics libraries or do any complicated setup. You can do this in any programming language because every programming language has print and loops. And it's a really simple way to just do some little artistic generative art programs and it's also surprising how sophisticated these programs can get. So I'm always on the lookout for new ways of introducing people to coding and I found that scroll art is a great source of programming projects for people to get into. 

BP I'm looking at hex portals right now and it's very hypnotic. A good screensaver is what it reminds me of. 

AS Yeah. You can add random numbers to it so that it's always generating something new. It's a lot like a lava lamp where it's never quite repeating and it's just kind of fun to stare at for a while. 

BP Sweet.

RD So speaking of introducing new people to programming, you've been a big advocate of introducing people to Python. How did you get started with Python and why are you spreading the gospel of Python?

AS Oh, man. Okay, so I think I got introduced to Python in about 2005, so I got in fairly early which was a whole lot of luck. I think back in that era, PHP and Perl were the main programming languages you would use to make especially web apps and that sort of thing, and I remember constantly learning new programming languages. I would learn Basic and then I learned Java and C and JavaScript and all these other languages, and then I learned Python and I just kind of stopped learning new programming languages after that. There's a joke that Python is the second best programming language for every task, and I found that that's pretty true. Even if it's not the best tool, it's a pretty good tool for almost anything you want to do. And I started writing Python programming books back in 2009, and back then, I just sort of threw them online and I didn't really think about them that much. But somebody suggested why don't I just self-publish them, so I did that and that was Invent Your Own Computer Games with Python, and people seemed to like it. But I also had the book online for free under a creative commons license, and that actually turned out to be a pretty good move because that allowed it to generate word of mouth and people could share the book and actually read it online. And people liked it, so I ended up writing a second book and then a third book. And then the fourth book, instead of self-publishing it, I approached No Starch Press with it, and that became Automate the Boring Stuff with Python, and I believe that came out around 2015. That was sort of the time when Python itself in the mid-2010s was really taking off. A lot of data science packages were becoming popular and Python itself was really taking off as a language. And so a lot of my story is just being at the right time, right place kind of a situation and I try not to forget that. I feel like if you hit a large amount of success in tech, it's really easy to give yourself the narrative that you're a super genius who knew what they were doing, but I feel like a lot of times it's just where you're working on a variety of different things and then one thing might really take off. I listened to your episode with Richard Hipp, the creator of SQLite, and I found that that's sort of the same thing. We're all just sort of working on these projects that we find interesting and kind of useful for other people and sometimes they just really take off. 

BP It's interesting to hear you mention its increasing relevance in the world of data science, and now Python is often discussed in the context of machine learning and modern AI. Did you have an inkling that it might become widely adopted and used in that world or was that not something that really occurred to you at the onset of your love affair with Python? 

AS Oh, it didn't occur to me at all. I just saw it as a pretty good scripting language that was really easy to use. There's a kitchen utensil company called OXO and they're the ones who design the can openers that have wide rubber grips and things like that, and from what I've heard, they originally designed kitchen utensils for people with arthritis or other mobility and grip issues. So they wanted to make these can openers and other tools that were easy to use, but it turns out everybody likes tools that are easy to use. And so Python is a little bit like that. It's an easy-to-learn programming language, but it turns out that even if you have 20 years of experience programming, Python is such a joy to work with and it doesn't really get in your way. It has a lot of features, it has object-oriented programming, but it doesn't force you to take the OOP approach. It has a lot of functional programming aspects. It has optional typing with its type hint systems. And you could ignore all of those features if you just want to write a quick throwaway script, but the sort of design makes it really flexible and adaptable for a lot of different purposes.

RD We just highlighted a discussion on the main Stack Overflow site about people discussing the best programming language to start with. 

AS That'll be an exciting conversation. 

RD It was. The two camps were C++, C, and Python, although some mad lad came in saying Assembly was the way to go.

AS Of course, always. 

RD What's your take on that? 

AS I always advocate that the best programming language to use is the one that you're most familiar with, or the programming language that whatever project you're contributing to is already using. At the end of the day, I feel like a lot of programming languages are all equally bad and insufficient to the task of making this complicated task of programming computers and writing software a manageable amount of complexity. Our human brains can't really collect all of the complexity of the software that we create in our heads all at once. I will admit, I really do like Python as a language and also as a community. And as I've gotten older and more experienced in my career, I find that it really doesn't matter how elegant or powerful your programming language or your software tools are. If you don't have good documentation, if you don't have other people who you can ask for questions, it really doesn't matter how great your tool is. Nobody uses it and it might as well not exist if it has such little impact. 

BP We did an interview, an older podcast which we can share with you after the show, with a gentleman named Pablo Salgado who's on the Python Steering Council, and I really loved that episode. There was a lot of things he mentioned about how that community works, which as you said, seemed really healthy. The dynamic within the steering committee and its relationship to the larger community seemed really good. To sort of reflect a little bit on what you said, every language is maybe appealing to someone or useful to some task, but none are quite up to the task of allowing a human to put their thoughts into code without some clunky abstractions or something. So have you yourself been playing around with Gen AI at all where the Holy Grail it holds out that isn't probably realized yet is that natural language will be the next interface. We'll ask the computer to build something, it will build it. There's a bug, we discuss it and take it from there. The scroll art seems decidedly retro, but I'm wondering if you're playing with any of this new stuff as well. 

AS Oh, yeah. So I'm working on the third edition of Automate the Boring Stuff with Python right now, and that's going to be coming out in the summer of next year– 2025. But the sort of elephant in the room that I have to address in that book is, you go on Reddit and all these other forums and you see so many people saying, “Well, is it even worth it for me to learn how to program? Because I heard that all software engineers were going to be replaced by AI anyway.” The technology is only five years away because the technology is always five years away. So I have to be very patient with how I go through this, and so much of what we do as software developers is just magic to people. There's the relevant XKCD comic, as always, where they say, “Hey kid, can you make a mobile app that can tell if we're inside of a state park?” And it's like, “Oh yeah, that's easy. We'll just use GPS coordinates.” “Oh yeah, and we also want them to be able to take a picture of a bird and identify it.” “Yeah, that'll be five years and 3 million dollars of development time to do that.” It's really hard for people outside of software to gauge how complicated some tasks are, or what software is capable and not capable of doing. So AI just seems magical, but I have a really dim and critical view of ChatGPT and a lot of these large language models and various tools. It's not like blockchain or NFTs. There is something there, but there is also just so much hype surrounding these tools. So what I have to tell people is, yes, it absolutely is worth it to learn how to program. Because I don't know, I hear a lot of other people talk about how these large language models are going to replace coders and how great Copilot is, and I wonder, do people have access to a version of ChatGPT-4 that I don't? Because whenever I use the tool, it generates code and a lot of times it's great and it's a little bit of a time saver, but also it often generates just syntactically invalid code. It makes up APIs that don't exist. It has all these problems that I, as an experienced software developer with years of experience, can identify as, “Oh yeah, that's a problem. That's a problem. It made this mistake,” and I have to go back through and clean it up and fix any bugs that it produces. And sometimes it actually is longer to do all of that than for me to just write the code by myself. So of course everybody is going to say, “Well, sure, that might be the case right now, but in five years, the technology will have improved,” and I've gotten to the point in my life where I think, “Well, I'll believe that when I see it.” The clear comparison is with self-driving cars, which are not self-driving at all, really, or self-driving in 98% of cases, but it turns out those 2%, that's really important that it has to get right there. 

BP What's interesting to me there is the expectation that, with imperfection, this tool sort of becomes useless, and so I can totally understand the sentiment that it would be faster for me to do this myself. But maybe if you think of it as an L1/L2 software engineer who's your intern, you can do something and it can do something else at the same time and then you go fix it up and that's okay. If you had just hired a human at some level of capability and they were writing code, you would expect it to have bugs and errors and people would work that out as a team through the push and pull requests. And with self-driving cars I kind of feel the same way. Humans are terrible drivers who make fatal mistakes every day that they don't have to, and self-driving cars, when they make a single mistake are sort of decried as an impossible technology that will never arrive. So I guess I'm just saying that we hold the AI to a different standard, but, Ryan, get us back on track before I take us too far off. 

RD I want to get back to Python. You said it's the second best language for almost any task. Are there tasks where it is the best language, and why isn't it the best language for all tasks? 

AS Well, I think if you just need to write a quick script, it is absolutely the best thing for that. Just write some 20-line program to do a task and then you'll forget about this program forever. It's so great for that sort of thing. This is sort of the area that Perl, I feel, occupied once. So Python is, I feel like, the best language for sort of sysadmin or DevOps kinds of tasks. And as far as making web apps, I feel like Python is at least tied for first place with all the other available options. I feel like it's probably easier to say where Python isn't that great. Currently Python really isn't used that much in gaming and it's not used in embedded systems, and also really anything where you need just sort of raw computational speed of course. But Python's strength is mostly in that you can produce readable, maintainable code with it, and software engineer time is so much more expensive than CPU time, so that's often a trade off that is absolutely worth it. I feel like no tool will ever be the absolute best at everything. It's sort of like how having a pocket knife is great for a whole variety of situations, but you would never want to use the blade of a pocket knife or a corkscrew on a pocket knife instead of an actual utility knife or an actual corkscrew. But it's that handiness and portability that makes pocket knives so useful.

RD It's interesting you talked about the sort of speed and downside. Python has become sort of the default language for data science and a lot of the AI backend stuff. Why do you think it's grown to such prominence in those places, and does that speed affect some of the AI performance?

AS I think it goes back to Python just being a language that's so easy to learn, especially if you're in some other career and you're switching to software engineering, or if you're a scientist or an academic and you need to write custom software to perform some task that there's just no commercial off-the-shelf software that can do for you. And because of that, Python has this growth rate that far surpasses other programming languages. And really, when it comes down to the performance of Python, the common saying is that Python is slow, but there's a sort of yes and no answer that I give to that. Back in the 90’s, the saying was that Java is slow, and that reputation that Java is slow lasted for far longer than that was actually true. And Python's slowness, which is actually not slow, it's just not as fast as other programming languages, it doesn't really matter because oftentimes for a lot of these systems, Python is just the glue language and it's attaching to code that's written in C or code that's written in Rust. For example, the newish code linter for Python, Ruff, which is written in Rust, the performance just blows every other code linter tool for Python out of the water. And I think we're seeing more and more ties between the Python and Rust communities and Python as a glue language for these other tools.

RD We've talked about Python for beginners. I think one of your books is about Python for beginners. Is that right? 

AS Oh, yeah. Most of my books are written for beginners. I think pretty much all of them to some degree or another, or at least that intermediate level or beginners. I just had so many thoughts about what would I have wanted as a kid learning to program but I just didn't have access to because I didn't know about these resources, or those resources didn't exist, or I just didn't have the language to say what I wanted to learn. All I knew was I wanted to make my own Mario game or my own Zelda games or something like that, but I didn't know anything about bitmaps or game engines or things like that. 

RD So if somebody's new to programming and looking to get started with Python, what is the first thing they should do? Or what are the first things? 

AS As far as my books go, Automate the Boring Stuff with Python is pretty good. I always intended that as more of a programming for office workers who are stuck in Excel spreadsheets and doing a lot of tasks by hand. But then I also have other books like Invent Your Own Computer Games with Python, which kind of goes into making mostly text-based games in Python. And I have a book, Making Games with Python and Pygame, that goes into 2D graphical games, and another one that's Cracking Secret Ciphers with Python, which goes into sort of code breaking and encryption and cryptography topics as well. I looked around at all the other existing books for that, and there's a lot of books about encryption and then a few books about breaking codes. There's a great book by Simon Singh on this topic about the history of it, but I really didn't see anything about, “Hey, how can you write simple little programs to do all of this code breaking for you?” And all of these ciphers are from before World War II, before we started using computers to do the encryption, so they were uncrackable because you would need a thousand humans with pencil and paper working around the clock to do it, but of course a laptop can crack them in a few seconds these days.

RD So you're not giving away deep encryption secrets there. Nobody's cracking SHA-256. 

AS Yeah, exactly. I do go in the very last chapter into the RSA algorithm, but it's a very textbook RSA algorithm. I really wouldn't use the code in that book to secure anything. Rolling your own crypto is a very common mistake to make. 

RD Right. I was just going to ask if there's anything you want to touch on. 

AS So PyCon US is coming up in a few weeks and it's going to be in Pittsburgh this year and next year. I really encourage everyone to go to PyCon. It's such a friendly and warm community. If you're just starting out, if you don't really know that much about programming, or if you have years and years of experience, I always have an absolute blast at PyCon. It was the first technical conference I ever went to, I think back in 2012. And then I started going to other tech conferences and I realized they're really more interested in trade show stuff and trying to sell you things and other things like that. But PyCon is such a community-focused conference. I always meet a lot of new people there. It's just such a great environment to learn more about software development and then the Python programming language.

RD Nice.

[music plays]

BP All right, everybody. Thank you so much for listening. As always, we want to shout out some folks who came on Stack Overflow and shared a little curiosity or maybe a little knowledge with the community. Since today's topic was Python, I've got two for you. There's a bounty expiring in three days. How to find best matching anchor text from paragraph and lists of titles. This one's dealing with pattern matching, string matching, elastic search in Python. So if you want to get yourself a bounty, head on over. And I wanted to shout out Alex S for asking the most popular Python question of all time. “What does the yield keyword do in Python?” 3.3 million other people had that question, so I'm glad you asked it, Alex. As always, I am Ben Popper, the Director of Content here at Stack Overflow. You can find me on X @BenPopper. Email us with questions and suggestions, podcast@stackoverflow.com. As you may have heard recently, we took your suggestion to talk to Dr. Richard Hipp. We are bringing guests on the show from folks who work in the software industry, and we're discussing topics that people email us about, so audience participation is encouraged. And the nicest thing you could do for us if you enjoyed today's show, is go leave us a rating and a review. It really helps. 

RD I'm Ryan Donovan. I edit the blog here at Stack Overflow. You can find it at stackoverflow.blog. And if you want to reach out to me with a podcast or article suggestion, you can find me on X @RThorDonovan.

AS And I'm Al Sweigart. I'm an author of many tech books that I publish for free under a creative commons license on my website, inventwithpython.com. 

BP All right, everybody. Thanks for listening, and we will talk to you soon.

[outro music plays]