Embedded - 368: Amazing That Any of This Works

Episode Date: April 1, 2021

Al Sweigart (@AlSweigart) spoke with us about getting better at Python programming.  Al’s book site is InventWithPython.com. You can find his books there as well as No Starch Press and Amazon.  ...Automate the Boring Stuff with Python Beyond the Basic Stuff with Python Cracking Codes with Python Invent Your Own Computer Games with Python Al’s personal site (alsweigart.com) has talks, videos, and a lot of code to look at. Or check out his github repo including the small text based games: https://github.com/asweigart/pythonstdiogames Al’s YouTube Channel, including his Calm Programming series. We also talked about: scratch.mit.edu - a fun way to learn to program where you are almost never wrong Fluent Python: Clear, Concise, and Effective Programming by Luciano Ramalho. PyCon and their talk videos  Online origami simulator (origamisimulator.org)

Transcript
Discussion (0)
Starting point is 00:00:00 Welcome to Embedded. I am Elysia White, here with Christopher White. Today we'll be talking about Python, no, not the snakes, with Al Swigert. Hey, Al. Thanks for joining us. Hey, thanks for having me. Could you tell us about yourself as though we met on the first day of PyCon at lunch? Yeah. Hey, I'm Al. I'm mostly known for writing Python books. The most well-known
Starting point is 00:00:35 is Automate the Boring Stuff with Python. And my 15-second description of that book is it's sort of a programming book for complete beginners who may or may not want to become software engineers but they're just office workers who are dealing with excel a lot but they'd like to learn how to program so they could write little scripts to automate all the little boring tasks that they have to do day to day excellent uh so i want to talk more about Python and the books you've written. But first, we want to do lightning round where we ask you short questions and we want short answers. Are you ready? Yes. Favorite Python module?
Starting point is 00:01:17 I auto GUI, which is also my own module, but the more I've worked on it, the more I've come to really love it. What Python module doesn't exist that you wish did? Oh, something that can very intelligently scan for people's resumes and then convert it to a standardized electronic format. Virtualenv
Starting point is 00:01:42 conva doc virtualenv I can't save conda after virtual env no one can virtual env conda docker or other and to use virtual env especially with the uh pip env uh module i think pip m was finally the the module that made virtual environments easy enough for me to actually use day to day. Should Python be the first programming language that someone learns? Absolutely. Python's a great programming language for beginners to learn because it has such a gentle learning curve and it hides away a lot of the complexities of programming. But at the same time, it's still a serious programming language that professionals use at software companies. How often do you use the Python debugger?
Starting point is 00:02:31 Not as often as I should. I've written a blog post about this where I know it's just adding print function calls is probably not the best way to debug things, but it's quick and easy, so I tend to do it. But yeah, the Python debugger is really handy. What's the worst part of the Python programming language? I guess that Python is called the second best programming language for any application. Python does a lot of great things, but usually there are certain domains where there's going to be a better option. But it's sort of like a pocket knife where there's probably better knives or screwdrivers. But as far as just having a Swiss army knife with all these tools and it's really portable and
Starting point is 00:03:19 handy, Python is really useful for a lot of different areas. Favorite fictional robot? Johnny Five from Short Circuit, mostly because he's an actual robot and not just CGI. Jupiter notebooks, yay or nay? Yay. I really like Jupiter notebooks, even though I haven't used them very often. But they're a great way, especially for people working in data science or in academia, to share their code with other people and just get introduced to Python in general. Do you have a tip everyone should know? Yes. So the best way to use the Python debugger is with the PDB module. And it used to be that you would have to import PDB and then call the set trace function.
Starting point is 00:04:14 But now you can just call the breakpoint function, which is just a global built-in python function now and being able to put that inside your source code and then rerunning your program to start the debugger at a certain point is really handy uh and then kind of maybe not a lightning round question maybe but uh how many versions of python instances or versions of python do you have on your computer right now i I'm going to need some time to count this. 2.6, 2.7, and then probably three or four versions of Python 3 or 5. So probably about six or seven. But do you have a Python 4 on there? Yes, it's my secret project that I'm working on.
Starting point is 00:05:03 Tell me about AutoGUI. Oh, PyAutoGUI. It's a module that I developed that allows you to control the mouse and keyboard from a Python script. So there's a lot of software applications that don't really have APIs, but you can have a program just click on buttons automatically or fill in forms. And so being able to use something like PyAutoGUI to do GUI automation, GUI as in graphical user interfaces, is really handy. And I feel like a lot of computer users, especially, in addition to computer programmers, would really benefit from this. If they have some boring repetitive tasks that they would just want to automate, just clicking a bunch of checkboxes automatically or filling in forms
Starting point is 00:05:51 automatically, PyAutoGUI can handle things like that. And I specifically made it so that it runs on Windows and Mac and Linux and also on Python 2 and 3 so that you don't have to dig up different instructions for different platforms. When you said GUI, I actually skipped one of our lightning round questions, which was what is the best module for making a graphical user interface? So maybe I should go back to that because that comes up a lot. Yeah, so I think of it as a tie between WX Python, which are the Python bindings for WX widgets,
Starting point is 00:06:32 mostly because they have such great documentation. And then there's also Tkinter or Tkinter. And it's actually not great as a GUI framework, but the great thing about it is it comes with Python, so if you have to just create some very basic, rudimentary Python GUI, then using TKinter is actually great, because then you can skip that step of having the user install an additional library. Is that based on TickleTK, which I was using 30 years ago?
Starting point is 00:07:09 Yes, exactly. And so it has a lot of legacy leftover stuff from that era. When I started looking at your books for this podcast, I picked up Automate the Boring Stuff, and it was weirdly familiar. You have your books online for free? Yes. I must have read the free version and then just recently picked up the, well, from Safari Online from O'Reilly. But I was thoroughly confused because I'm like, where is this happening? Yeah, that got started sort of by accident, but it was a very fortunate accident. I was working as a software engineer, and when I started writing books, I would just put them online for free under a Creative Commons license, which makes it free to share and distribute non-commercially. And I didn't really consider writing or being an author as my career. I just thought, well, this is something that I like to do for fun as a side hobby. And people seem to like it. So I
Starting point is 00:08:18 eventually self-published the first few books I wrote and just kept doing that more and more. And it turns out to be a really good thing because having it free online allows people to build up that word of mouth promotion for it. Otherwise, all of my books would have just been yet another self-published book sitting on an Amazon entry somewhere, and nobody really has ever heard about them or nobody would really know about them. But mostly my aim with my career is, with the success of Automate the Boring Stuff, I'm able to have this as a career. But at the same time, I don't want to really maximize the amount of money I make from it as much as maximize the number of people who can access this and just lower the barriers to access so that other people can learn how to program. And you've written several Python books that I know about. Automate the Boring Stuff,
Starting point is 00:09:19 Beyond the Basic Stuff, Cracking Codes, and Invent your own computer games. Are there others? Yes. I wrote one book called Coding with Minecraft that uses a Minecraft mod called Computer Craft that adds these programmable robots into the Minecraft world. I joked, I called it Automate thecraft stuff but uh that uses the lua programming language uh to program the robots and i think that's that's the uh oh and i've also written a scratch uh programming book as well scratch is this programming environment made for kids um you can go to scratch.mit.edu and it's completely free and runs in your web browser and you can just easily make these simple little programs with their code blocks that you snap
Starting point is 00:10:13 together. And it's a really cute language. It's easy to build stories. Yeah. Because you can do characters and build actions of people or characters. And I like Scratch a lot. Yeah, the more I use it, the more I realize they made a lot of really smart choices with that programming language. I read one paper about it, and it pointed out that there's no error messages in Scratch. They have some pretty sensible default behaviors, but kids who most of the time will have a hard time typing out code, and so with the snap-together blocks, they can mostly just use the mouse. But whenever I've tried to teach, especially young kids programming Python,
Starting point is 00:11:00 one hurdle that they always have trouble with is typing out code and then getting some error message. And then they feel bad because they got the programming wrong and then they feel like they're dumb and they can't do programming. But by not having error messages and just having unexpected and sometimes really hilarious weird behavior from their programs, then they're encouraged like okay that didn't do what you expected why did it do that and you can look at it it doesn't just shut them down immediately with some inscrutable error messages about missing a semicolon or something like that i mean there are compiler errors and it sounds like they've eliminated those and there are runtime errors and then there are the semantic errors, the ones that are based on a failure of understanding.
Starting point is 00:11:47 Yes. Have they eliminated the runtime errors as well? Exactly. Oh, that's genius. Yeah. I mean, it'll have some odd moments. I think if you try to divide something by zero, it'll just evaluate it to zero or some other strange message. But there's no part where your program will crash and just stop running.
Starting point is 00:12:11 It might start doing something you really didn't expect. But yeah, the Scratch programming environment has never told you that you have failed. Yeah, I could get behind that. That would be nice. Okay, so one of the things people say about Python is that it takes a day to learn and years to master. Do you agree with that? Oh yeah, I'd certainly agree with that. I gave one talk about the Python object model and all these low-level details about Python. And one of the things I mentioned in that talk was that I'd been using Python for over a decade. I had even had jobs at companies where I'm programming Python professionally. And just a lot of these small details and tiny misconceptions that really
Starting point is 00:13:13 didn't affect the code I was producing. But at the same time, I was completely unaware of how everything in Python is an object. So even integers and floating point numbers are still considered objects in Python and how this affects assignment and other small details. And these are things that you're almost certainly never going to encounter except in really weird esoteric cases. But I guess it's a credit to the language that Python can still be so useful, even with just a light understanding of it. And that's what I mean when I say that Python has such a gentle learning curve. One of the things I see a lot and have done myself is consider myself a competent programmer in C or C++ or what have you. And then when I come to
Starting point is 00:14:07 write a Python script, I just kind of throw all that to the wayside and write something that's not very, you know, well-written from a design standpoint or an architecture standpoint. I don't think it's language's fault. Is it just that I'm writing a script, so I don't have to care, or is it a personal failing or is there something about python that makes competent programmers just kind of yeah python is a really versatile language and a really simple language um i'm really glad that they've added features such as type hints so that if you're going to create massive production systems that have to be running 99.99% of the time, the newer features of Python help you do all of that. But for the most part, as the Randall Munroe of XKCD, the webcomic said, hello world in Python is one line. And there's nothing like in Java where you have to type, you know,
Starting point is 00:15:07 public class hello, public static void main, string args, bracket, bracket. And then, you know, if you're learning a program, you have no idea what all of those words mean. And it's just sort of mysterious abracadabra. But with Python, it's fairly easy to get started and then just sort of knock something out. And if you're only... I feel like that's a lot of
Starting point is 00:15:31 what casual programmers and hobbyists really just sort of need from a programming language is making the simple stuff simple. But I've been using Python a lot in the last three years. Professionally. Both of us.
Starting point is 00:15:50 Professionally. But I just found out about Dunders about a month ago. There are so many things about the language that seem hidden. How do I learn those? The precise answer to that is not a book that I wrote, but a book from O'Reilly called Fluent Python by Luciano Romalo. And it's about, I think, a thousand pages maybe or 800 pages but uh it's the book where once you've learned all the basics of python and and you're uh you have a lot of knowledge and experience but you want to learn all these tiny little details this is the book that goes into all of these uh details about
Starting point is 00:16:44 the python language that sort of most of these details about the Python language that most of the time really only core Python devs know or people who have a decade of experience with Python will know. Outside of that, probably the PyCon videos are a great way to learn about tiny little features of the Python language. So PyCon's talks are all recorded and they put them online for free. And I find those are a really useful source. But Fluent Python, which I have on my shelf and I've mostly read most of it, I sort of take bits and pieces of it at a time. But that one book is really sort of what takes you from intermediate to advanced Python programmer, in my view.
Starting point is 00:17:35 One of my problems is that I am also in the same level of competency with TensorFlow. And I'm a little bit more confident with NumPy since I've had a lot of MATLAB in my history. But sometimes I don't know which one I'm asking about. Could you write a book that can... No, wait. What was my question there? How do you tell when you're using NumPy and how do you tell when you're using Python?y and how do you tell when you're using Python?
Starting point is 00:18:05 I don't know. How do you go from typing at it and printing to being relatively confident you are using the right, I don't want to say accent, being truly Pythonic. Idiomatic. Idiomatic Python. I'll tell you as soon as i figure it out okay so with um with the latest book that i wrote beyond the basic stuff with python i i wanted to write a book that was sort of bridging the gap between beginner and intermediate um as far as uh best practices not just with python but with coding in general.
Starting point is 00:18:47 And so I write a little bit of how to write good comments and the basics of just using Git and source control and why you would want to use that. And then I also go into Python object-oriented programming and why do we even have classes and that sort of thing. And throughout that book, I try to just hedge my bets because whenever I give any advice or say things are best practices, I just say, well, these are what I consider to be best practices.
Starting point is 00:19:19 Because in the back of my mind, while I was writing that book, every time I finished a paragraph, I kept thinking, okay, what are the one-star Amazon reviews going to say? It's like, well, Al Swigert says this, but really he's wrong because of some other things. And I think the more experience I get with software development, the more I realize that nobody really quite knows what they're doing. And it's amazing that any of this works as well as it does i mean yeah you can even find you know large corporations like google or amazon and and aws will have some outage that causes half of the internet to just suddenly break um for an hour or so and and and you begin to realize that, you know, we, uh, software engineering
Starting point is 00:20:06 is, um, involves a lot of duct tape as, as well as a lot of, you know, very principled engineering and, and careful analysis and construction. Um, but then also a lot of times we're sort of just winging it. Uh, I kind of of hate that i hate writing duct tape scripts i mean i guess part of it is with with working with embedded and microcontrollers and having to use every cycle or squeak out every nano amp or try to try to find the last 10 ram bytes so that i can do something new i don't like the uncertainty i like i like to have more confidence that i've done the best that i could do which is at least in the top 10% of what anybody else could do. Oh, yeah. That didn't come out right.
Starting point is 00:21:06 It's at least as good as most people. Yeah, but I completely understand that because I feel that way all the time, too, especially if I'm working on, like, I'm typing on some mobile app and the screen doesn't refresh as fast as I'm typing, which seems like, with all the computing power we have, the screen doesn't refresh as fast as i'm typing which seems like with all the computing power we have the screen can't put letters on the screen uh as as fast as i'm typing that seems like a very 1980s sort of computer problem and and i just wish like oh i wish things were just a lot more simpler where, you know, we just had the text only displays and ASCII art boxes for the graphics and things like that. Go for inlinks forever. Yeah, exactly.
Starting point is 00:21:57 But then I realized, well, that's probably just because I'm a that's a product of I'm a product of my time and it's like well I started learning programming in the 1990s and that was the best time for programming but um at the same time yeah I guess it's rather unfortunate that just technology and computing keep progressing um some of the things that I say to myself to reassure myself that it's okay it's as long as it works it's works and it's fine it doesn't have to be absolutely perfect i i remind myself that you know this sentence that i'm speaking right now has taken up literally billions of nanoseconds so why am i spending so much time worrying about getting every single nanosecond of performance out of my code? There are certainly domains where this is very important, embedded being one of them,
Starting point is 00:22:53 or if you're writing the code for a nuclear reactor on a Mars rover or something like that, you need to make sure it works and you need to make sure that it's performant but just from coming from my point of where I am where I'm writing Python code and I'm writing desktop applications you don't have to have everything work absolutely at the best level that it can and really when I'm programming and I'm writing out code, I tell myself, you know, it's likely that within two or three years,
Starting point is 00:23:31 the code I'm writing right now will be forgotten or replaced. It's not like I'm building some cathedral that will last for centuries and centuries. So really, it just has to work, and it has just has to work and it has to work correctly and it has to work fast enough and um yeah and just the there's the saying that software engineer time is so much more expensive than cpu time and you know if if you can get your algorithm to to run a few milliseconds faster but it takes takes eight months to get there, have you really saved all that much time? Yeah, and I mean, that definitely depends on what you're doing. And most of the time, the answer is no, it was not worth it.
Starting point is 00:24:21 I picked up your Beyond the Basics stuff, and your description of it was right on. It was still for relatively new programmers. It was a nice introduction to engineering as opposed to just Python. python um and and i appreciate the beyond fluent or the fluent python uh to to look at because i think that will be interesting one of the things that i finally untangled in my brain from your book was iterators and how they work can you can you describe that for everyone okay so this is this is another part of python's gentle learning curve is when you learn about for loops and uh normally the the syntax is for i in and then you call the range function and you pass 10 to the range function and this will cause the for loop to loop 10 times. And you just learn about that. It's like, okay, if I have some code
Starting point is 00:25:29 that I want to run a certain number of times, then I can use a for loop with this range function. And that's about it. You have that high-level understanding. But technically, you can think of the for loop in Python as sort of like a for each loop. Where in JavaScript, if you have an array of various values and you want to run some code assigning that i variable to each of the values in that array, then you could use a for each. And that's sort of how Python's for loop works.
Starting point is 00:26:05 But since it's not called for each, you don't really think of it that way you just remember range function that's that's all that's all i need to know um so technically the range function returns in iterable uh because it is in iterator oh i keep even i get the terminology confused but uh it returns an iterable object, and this object basically says, okay, every time you want to get a value from me, I can give you the next value.
Starting point is 00:26:35 So this works for strings, which are just sort of one single character after another, or it can work for lists, where it's one element in that list after another. And iterable basically iterates over all of the objects, and it can return one object or one element from this collection of data at a time. And it'll go through it once, and then when it reaches the end, it's exhausted exhausted itself and you'd have to get a new iterable object
Starting point is 00:27:06 and so a range object returns this iterable object that can just go through the integers 0 through 9 if you call range 10 for example and this is kind of nice because in the old days of Python 2 I believe the
Starting point is 00:27:22 range object would just return a list with the integers 0 through 9. And normally that was fine because that's not that much data. But what if you wanted to do something 1 billion times? And then the range object would return the integers from 0 to 1 less than 1 billion, which would just take up gigabytes of memory. And if you think about it, well, you don't really need to store all of that data in memory. You can just have the iterable object remember, okay, I last returned the integer 3, and the next one I'll return is 4. And also, then I'm going to stop after I return 9. And so in Python 3, the range
Starting point is 00:28:05 function was changed to have this behavior using iterables. And again, all of this stuff is these are details you don't necessarily have to know if you're a beginner or intermediate.
Starting point is 00:28:23 But once you do know this, then you can start thinking about, oh, and so I can also use a for loop to iterate over all the keys or values in a dictionary, because that can be an iterable object. And I could make my own iterables, sort of like if you had a function that for some reason you needed to iterate over prime numbers, starting with 2 and then going to 3 and 5 and 7 and so on. Instead of creating a list of these prime number integers, you could just have an iterable object and save a lot of memory on that, and then use the standard
Starting point is 00:29:05 for loop uh for this or if you've come up with some sort of weird object i don't know uh let's say um robotic octopus i i might have tied myself back myself into a corner with this metaphor and you wanted to run some code for each of its eight arms um and And you don't want to write some weird custom function. Well, you could just have the robotic octopus object return an iterable object that returns each of its eight arms in a sequence. And then that way you can just use Python's regular standard for loop with your robotic octopus object um four arms in octopus
Starting point is 00:29:49 yeah and it it allows you to write the code that you you can write ends up reusing a lot of python's built-in syntax you know things like for loops in this case. And there's a lot of things where once you start learning about iterables or the dunder methods, you find that you can actually, you don't have to reinvent a lot of these things because they already exist in Python, which not only keeps your code short and simple, but it also just establishes this sort of standard convention that other Python programmers can see. And instead of inventing your own conventions that then your teammates or other contributors to your project would have to learn about.
Starting point is 00:30:41 One of the things that made it click for me, and I know iterators are in C++ and I've seen them there, but I've never thought about them other than as you can run for loops over them. But you had a variable equal to the range 10. And so the variable r equal ranged n. Then you call r.next, and it gives you zero. And you call r.next, and it gives you one. r.next gives you three until you get all the way to nine. And then when you call r.next, it throws an error. And so inside the for loop, that's what it's doing. And I just had this little tiny bubble go off in my head that
Starting point is 00:31:27 said, oh, and then it linked over to generators, which are a different thing and made those make sense anyway. Yeah. It's a lot of these things where you use it, I guess it's sort of like driving a car and all you need to remember is to keep the gas tank full. But then you can start learning about how everything starts working under the hood. And Python's really great about hiding all of those details from you if you don't need to know about that stuff, say if you're just learning how to program. But then later, once you do need to start paying attention to performance or writing a quote-unquote Pythonic code that the other Python programmers on your team will understand, that's when learning all of these details really starts coming together. And that's where, that's one of the difficult things because when I started out writing Python, I was just doing the things I knew from C, for loops and what have you, and they tended to be sort of slow.
Starting point is 00:32:34 And you can write, Python offers a whole bunch of much more compact and advanced features for doing things to collections of objects, list comprehensions, and the map function. Do you feel like those, at what level do you think people need to know about those sorts of things? Can most people get by without ever learning those or those things that everyone should really learn because they're much faster and much more compact code? I feel like everybody should learn them, but not today. And you can just keep telling yourself that day after day after day, probably. Yeah, it's something that you were just all these tiny little details about Python that I actually didn't know. And it didn't really come up all that often. understanding of the tools that you're working with can allow you to to skip a lot of basic mistakes um i remember one time when i was at a at my previous job i was at a code review meeting with with other members on my team and we were looking at a web application product for a router
Starting point is 00:34:01 where you can set up different pass and block rules for for the network traffic that was going through and we uh you know you had all these fields and we had set up a framework so that we had validators for this so if it says you know you need to enter a number between zero and a hundred and you filled in something else it it would show a little red mark and tell you to correct that. And for coming up with the rules for these pass block rules for the network traffic, you could also type in a regular expression just to find a pattern of traffic that you would want to block, say. And one of my co-workers said, said hey can we write a regular expression as a validator for regular expressions and this tiny untapped part of my brain from uh computer science undergrad uh just suddenly caused me to say like actually you can't because regular expressions, the strings have nested parentheses.
Starting point is 00:35:10 And in order to correctly find that, you can't use a regular language. You need a context-free grammar and a stack data structure to keep track of all that stuff and blah, blah, blah. And all of this just spilled out. And it's like, is this the first time I've ever used my computer science degree for something? And I realized like oh okay i mean like my co-worker was just being flippant uh with that comment um but at the same time i realized you know what if we had thought oh we should write a regular expression that can match regular expression strings we could have spent weeks on that without realizing that actually theoretically no you you can't do that it's impossible you
Starting point is 00:35:45 can probably get something really over-engineered uh and spend a lot of time uh trying this out but uh in the end it's technically you know technically you this is an impossible task like regular expressions just aren't that expressive enough, I guess you could say. And so it's these things where you don't have this foreboding sense of doom, but there are times when having a little bit of knowledge can save you a ton of work. So it is useful to do a deep dive into the tools that you're using. Talking about limitations, you're going back to limitations. You have a GitHub repo, Games by Example? Yes. Tell us about that. So this was something that I started, I think, around 2018, maybe before.
Starting point is 00:36:50 But it sort of came out of my first book, Invent Your Own Computer Games with Python, where instead of teaching programming concepts in that book, I just sort of started with the complete source code for a small game. And then I would go line by line explaining all the different parts of Python syntax that came together to make that game work. And I thought like, well, this is really great because I remember when I was trying to learn how to program, I would read some programming books that talk about syntax and they have code snippets, which you can't actually run if you type them into the computer. And it just helped me so much more to see a complete example of some program that did something,
Starting point is 00:37:38 even if it was just something like a guess the number game. And so I thought it'd be really nice to have a large collection of programs that are like that. And so I started creating a whole bunch of those. And over time, I started developing all these rules for what these programs should, how they should be constructed. And so some of them are, they should be short, they should be simple. You know, if there's a complicated way to do something and a simple way to do something, even if it's a little bit longer, just go with the simple way because you're writing code not for performance, but to be understood by beginners. And another one was to limit myself just to text as far as the input and output. So I'd use Python's print and input functions only. So these really wouldn't have graphics per se unless I started creating some ASCII art kind of graphics,
Starting point is 00:38:33 which would work surprisingly well for a lot of different things. Like I could create, I create a small blackjack game and it has these tiny little cards that I draw on the screen with underscores and the vertical pipe character. And so after a while, I just started growing this collection. And it's actually going to be in a future book that's going to come out later this year, the big book of small Python projects, where I didn't really want to go into, you know, teaching Python per se with this,
Starting point is 00:39:09 but just say, hey, here's a giant collection of programs that are under, you know, 250 or 300 lines of code. You can just copy them, you know, yourself, type them in yourself, start modifying them, see how that works. And my hope is that even though it looks really old school because it's all just text and it's kind of boring, but at the same time, you know, it only takes about 20 or 30 minutes to type these in. And if you amuse yourself for 10 minutes before moving on to the next one, I'd still call that a win.
Starting point is 00:39:44 That sounds like your childhood, Christopher. Yeah. I mean, I just was about to say, you know, well, this is a great idea because I haven't seen a lot of this kind of thing recently where when I was a kid, it was, you know, you'd get a magazine or something and it would have, you know, a game and it would be on three pages and you'd type it it in been basic or something. And it was a great way to learn because it was everything self-contained and you didn't feel like you were spending hours trying to get something to work. And this is these bite-sized things are just great. Yeah. And part of me is really worried that I think this is great because this is how I learned
Starting point is 00:40:23 to code. And, you know, if you think about younger people today, they're probably not even really on laptops so much as on phones and tablets instead and using social media websites and that sort of thing. And so I wonder, like, oh, is this just, am I just old? And that's why I think this is a good way to learn that program. No, you're absolutely 100% correct. This is a good way to learn that program. No, you're absolutely 100% correct. This is a good way to program. Do you know what a speak and spell is? Yes, I do. Yeah, and I guess it touches on that problem with software today just being really complicated.
Starting point is 00:41:03 Like I would teach these Saturday morning programming classes to kids, and I'd say, hey, okay, we're working in Scratch. What do you want to make? And they would say, Minecraft. We're going to need more than 45 minutes to do that. It's, you know, software today is just so complicated and has so many working parts and you have to install these libraries and then the libraries don't work and you have to debug that
Starting point is 00:41:30 and spend time on stack overflow where whereas these these small text-based games um they're all text they all exist in one file you you don't have to load other libraries or have some virtual environment set up or anything like that. In fact, since it's all in one file, you could just select all, copy and paste it to Pastebin or to an email and send it to your friends. And I wanted to get rid of as many of the barriers to just getting started and getting something running even if it was really tiny and uh and not all that fun um but yeah using just modern game design principles it's i'm really pleased with with what i've managed to come up with um a lot of those old you know the like bite magazine uh listings of the source code in basic for some game uh i've gone through a lot of those old books and i realized that a lot of those games just aren't really all that fun no blackjack i mean that's kind of fun but also you videotaped yourself writing it? Yeah. Videotaped.
Starting point is 00:42:45 Oh, God. I'm so old. Were you listening to a phonograph at the same time? I don't even know what a videotape or DVD are. Did you save it to a floppy disk? Sorry. You know, we're just... I think archaeologists are just going to be digging up our bones and then finding a floppy disk icon that has just like transcended millennia.
Starting point is 00:43:11 And they'll be like, we think this might have been part of some fertility cult back then. No, they're going to still be using that icon 3000 years from now and nobody will know what it means anymore, but it'll still be in all software. It's like, oh yeah, that's just the save symbol. Yeah. It's like a rune um but yeah i so i have videoed myself um uh typing the code in for a lot of these really simple uh programs and i call it the calm Programming series. Mostly, I wanted something that was different from a lot of the other programming tutorials you would find on YouTube. I really like these channels that do furniture restoration
Starting point is 00:43:54 or metal tool restoration. Building violins. That's the one for me. Building instruments that are just so amazing. And especially the ones where they don't do a lot of talking. There's very little narration. There's one called Primitive Technology where it's this guy just wearing gym shorts somewhere in Australia,
Starting point is 00:44:16 and he makes flint stone axes and starts fires and builds mud huts and everything, and there's no talking whatsoever. You can turn on the closed captioning for limited explanation of what he's doing. But these are sort of casual things that I just like to have on when I'm just really tired and I don't want to pay much attention to how things are working and just something interesting to look at. So I started creating a video series where I actually have the camera just on my laptop screen,
Starting point is 00:44:50 which requires a whole lot of setup just to get the camera angled correctly and the brightness setting on the laptop screen working. But you can just see me sort of typing out the code for these really simple 250-line programs. So the first episode was covering the Blackjack program, and the second episode now has me typing out the code for Conway's Game of Life. But you can sort of just see my screen as I'm typing this code out. And I make sure that all the programs have a lot of comments
Starting point is 00:45:27 to explain what's going on with the different parts. And I wanted something that was just sort of for people who just want to see some content that is very low-key and something that they don't have to really think too hard about. And then after the end of 20 or 30 minutes of this, you have the small little program. So it's a formula that I thought of where it's easy for me to create these videos because I don't have to do a lot of narrating and talking, which is always a headache when it comes to editing it later. I have to take out every single uh and um and weird mouth noise that I make into the microphone.
Starting point is 00:46:06 But this is just sort of rather soothing. You just hear me typing on the keyboard, and you can just watch as the code comes together. And I'll start running bits and pieces of it as I develop it, so that you can see how all these different functions that I write come together to produce this final program. And I have a lot of these programs, these text-based games and animations and things like that. So I have a lot of material for future videos. And so you aren't, are you designing them as you're doing this? Or are you just sitting down with the design you already have? You aren't just typing out of a already done sheet of paper are you that is exactly what i'm doing
Starting point is 00:46:52 almost i i um so the start of the it's sort of like those cooking shows where you know they they mix all the ingredients but they've all been pre-measured. And then they put it into the oven, but then in the same shot, they pull out a already cooked thing from the oven to show you. And so it's sort of taking away all the boring parts and trying to figure out weird bugs or things. But at the start of each video, you see me just setting up my laptop and getting a cup of
Starting point is 00:47:27 coffee and putting all of that on the dining room table. But what you don't really see is that I have a second laptop that has the source code for the program that I'm writing. So it's a bit unnatural in that it's just me straightforward sitting down and typing out this code. And technically, you could just sit down with the source code yourself and then just read through it. But these aren't so much tutorials as just calm, soothing videos that you can watch when you don't have anything else that you want to watch or have to focus on too much. But you want to see some program come together. Whether or not there's a large audience for this, I don't know, but I guess I'll find out. You talked about being a developer.
Starting point is 00:48:20 Are you primarily a technical book author now or do you still do development um yeah i'm being an author is my full-time career now as of uh i i forget i think it's 2013 is uh when i left my job as a software developer and originally i was thinking well i'll just spend a year to finish up this book I'm working on called Automate the Boring Stuff with Python. I have no idea if this will take off or not. But it's sort of like winning the lottery where this has really worked out well for me, although I'm not really sure how I could give advice for other people to follow the same path. But yeah, with the way that book took off, I just thought, well, I can spend another year.
Starting point is 00:49:10 I have some other ideas for online courses or videos or other books that I want to write. And so I would just keep working on those. And two years became three years, became four years. And now it's a really great scam, writing programming books. Hopefully, I will never have to get a real job ever again. It is a good way to become extremely wealthy. Oh, writing books. Yeah. Writing technical books is definitely where the big bucks are. I feel bad because people will email me on occasion and say like, well, hey, I have an idea for writing a technical book. Do you have any tips? And my honest answer company that I still had time after work.
Starting point is 00:50:07 I wasn't working 60 or 80-hour weeks at a startup or something like that. I had my health, and I had free time. And Automate the Boring Stuff with Python was actually the fourth book I wrote. I had first got started in 2009, just sort of creating tutorials that turned into books. And people liked the first one, so I wrote another one, and people liked that, so I wrote another one. And so I had all this practice writing books. And then also, that sort of early 2010s, mid-2010s, that's sort of when python really started taking off as a programming language so i had several years of experience with this programming language um and and i just
Starting point is 00:50:53 had sort of you know out of sheer luck you know picked the right horse uh in this race that uh that turned out really well so i i I try to keep that in mind before I let my ego grow too large. That, you know, my life could have easily taken a different path and I would just be, you know, some software developer that nobody had ever heard of. Which isn't a bad thing.
Starting point is 00:51:24 Oh, yeah. Yeah. Oh, for sure. But it's um whenever i go to paikon i i kind of feel like a rock star because people have heard of this book that i've written and and so like sometimes what my autographer takes selfies with me and at first i thought like that's weird what um but then i learned like no, no, just do it. People get a kick out of it, I guess. But people also tend to think I'm a much better programmer than I actually am. They'll ask me for advice on machine learning and AI, and I actually have no experience with that. But I could make stuff up and speak authoritatively on it if you want have you had any experience with the circuit python or micropython or other embedded pythons
Starting point is 00:52:12 very little um uh i remember telling my friend a bunch of the hobbies that i have uh which were just sort of writing software and writing these tutorials and things like origami. Wait, wait, origami? Let's just stop everything and talk about that. Yeah. I'll be back. I'll let you guys talk for a while. Yeah, this was, you know, as a kid, I kind of liked doing origami folding. So my background is my father is white my mother is is japanese and so she would show me like how to make the crane and i think a couple other really basic things and
Starting point is 00:52:54 and then i would find origami books and i would not be able to do any of the models in there because the the folding diagrams there would always be you know i'd be five steps in and then there's some steps i just don't know how to make my piece of paper look like the thing in the book and at that point i was kind of just stuck and i didn't know it like i didn't know anybody else who was an origami master who could help me through this and then um you know sometime in the 2010s i think i i had the thought hey i bet there is like a million origami folding videos on youtube i could just look up so many and yeah and it's great because now you can make all the really cool uh models uh so i can make like a cat and a t-rex and a horse and things like that.
Starting point is 00:53:45 And because you can actually see how they fold each step and you can rewind and put it in slow motion if you have to. And so I've gotten more into that as well. And so, you know, I was telling my friend like, oh yeah, I like origami and writing books and software and things like that. And she told me, well, you know, the one thing that all those things have in common is that they're cheap hobbies. That's true. My origami bill is much less than an instrument bill.
Starting point is 00:54:18 Why are you looking at me? I don't even use origami paper most of the time. I'm just sort of, you know, getting stuff out of a recycling bin just to play around with. And so I feel like I never really got into hardware because you have to spend money on these components and on a multimeter and an oscilloscope and a bench and all of these other things. And it's, you know, writing books is nice because I can do that and then put it online and share it with tens of thousands of people. And I pay about like $12 a month for web hosting to do that. It's really great. And, you know, the same thing with videos and other types of software and content like that. Whereas if I made a cool blinking light thing in hardware,
Starting point is 00:55:12 being able to mass produce that and share it with people is just such a daunting task. I've never really gotten into it. Well, let me recommend the Raspberry Pi Pico, which runs the different Pythons and costs $4. That is very nice. It's a nice little chip. It's pretty easy to program. Lots of support, lots of community. And $ just sort of reminds me, because I hate telling people how I learned to code, because I start when you're really young and you just have to have years of experience and I can't possibly do that. But really at the same time, you know, back in the 90s when I was learning how to code, there was next to no information. And today you have Google and Stack Overflow and YouTube tutorials and, you know, free books online. And there's just so much information where you
Starting point is 00:56:26 know my head start really didn't count for all that much in in the long run and you know these days wow you can you can get a python programmable board for four dollars and start creating things that's just incredible um i remember just as a young teenager i was like i want to build robots um but i didn't know anything about building robots i i kind of like i knew how to use a soldering iron sort of and i figured out like okay connect batteries to this switch to this motor and uh but you know like the housing i just you know cut apart like aluminum cans but you know the you know quote unquote robot that i created would just sort of like roll around in not quite a straight line and uh and then probably get stuck on the carpet or something like that and it was like this is not as cool as Johnny Five
Starting point is 00:57:25 from the Short Circuit movie that I really loved. And I tried finding books on robotics, but they were just so far ahead of where I was, and I didn't really have anyone to explain things to me. So yeah, I just never really got into hardware or embedded programming at all. Well, there's a lot more out there now, should you want to look at robotics. And origami, by the way, is one of the ways that I use Python regularly. Oh, really? I do curved crease origami, which requires more math in order to know where the curves are going to happen. That's where you sort of bend the paper instead of folding and creasing it? You score it, and then you fold along the score, which is curved,
Starting point is 00:58:18 which means that your result in the end has to be a piece of paper that's curved. Oh, I see. result in the end has to be a piece of paper that's curved oh i see um and then so i make i i just finished a giant uh exploration of snails and how to make snail shells and it was a whole generative python thing because should they be in a plane? Should they be conical? Should they curl up onto themselves just like nautiluses do? There are a lot of parameters this because there are some sort of origami software-related projects that I've been wanting to do. Mostly as just sort of creating like a CAD kind of setup for paper folding so that you can get these animations that you can view from any angle. Because the main problem with all the YouTube origami videos is that you have somebody's big human hands blocking the camera shot most of the time. Well, you need the SVG files. But there are some origami simulators online.
Starting point is 00:59:41 There's one, Amanda Gassier, that's how I'm going to say that, has a really good one with some neat patterns and some of what you're talking about. They don't do as much curved as I do because nobody likes curves as much as I do. Yeah, I have a GitHub repository. I'm happy to share pictures. Happy to share pictures. Happy to share SVGs. Okay, I should probably let you go.
Starting point is 01:00:17 Or we're going to talk a lot more about origami when we probably should still be talking about Python. Al, it's been really fun to talk to you. Do you have any thoughts you'd like to leave us with? Yeah, one thing that I really love to plug is just the Python community in general, and also PyCon, the Python conference, which unfortunately is going to be virtual and online again this year due to the pandemic. But PyCon was the first technical conference that I ever went to. And I was just really amazed. It was great. And PyCon is also a conference where it's not $2,000 for a ticket
Starting point is 01:00:53 because they expect that your corporate employers are going to pay for it. It's something that ordinary people can go to. And even if you're a complete beginner and new to Python or programming, it's a great way to just show up and people are really friendly. And, you know, you can go see some of the talks, but you can also just sort of hang out in the hallways and start chatting with people. It's, you know, PyCon has become this way that I see my friends from across the country or across the world every year, except, unfortunately, for the last couple.
Starting point is 01:01:31 And so I really want to encourage people to look up PyCon just for themselves to attend, or even if they just want to watch some of the videos from previous conferences. Those are all online as well. Our guest has been Al Swigert, author of a number of books, including Automate the Boring Stuff with Python and Beyond the Basic Stuff with Python. You can find his books on No Starch Press, where buying the physical copy also gets you an electronic one, or you can get it from one of the other booksellers. Also check out Al's website, inventwithpython.com, or you can get it from one of the other booksellers. Also, check out Al's website, inventwithpython.com, if you want a preview of those books. And if you want to find his Udemy course or videos or whatever, links will be in the show notes.
Starting point is 01:02:18 Thanks, Al. Thank you very much. Thank you to Christopher for producing and co-hosting. Thank you to most of our Patreon Slack group for questions about Python that I did not ask Al. But some of you, Monty Python was not appropriate. Also, thank the rest of you for listening. You can always contact us at show.embedded.fm or hit the contact link on embedded.fm. Now a quote to leave you with from Nietzsche. The snake which cannot cast its skin has to die, as well the minds which are prevented from changing their opinions.
Starting point is 01:02:58 They cease to be mind.

There aren't comments yet for this episode. Click on any sentence in the transcript to leave a comment.