Al Swiger is back on Talk Python. This time we're inventing our own computer games.
Has anyone ever asked you for a resource to get started on how to learn programming or
how to learn Python? Well, one excellent and fun option is Al's book, just updated,
called Invent Your Own Computer Games with Python. And we'll be digging into it this episode.
It's Talk Python to Me, episode 106, recorded March 20th, 2017.
Welcome to Talk Python to Me, a weekly podcast on Python, the language, the libraries that
ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter,
where I'm @mkennedy. Keep up with the show and listen to past episodes at talkpython.fm,
and follow the show on Twitter via at Talk Python. This episode is brought to you by Intel and Get
Stream. Be sure to check out what they're offering during each of their segments. It helps support the
show. Hey, everyone. Before we get to Al, I want to share three pieces of news with you.
First two, I've launched two new courses this week. The first one, I partnered with Dan Bader,
and it's called Managing Python Dependencies. This is a deep dive into how you need to manage your
dependencies in Python, understanding pip, understanding requirements, and actually figure
out what makes a good dependency in the first place. How do you search through all the possible
packages on PyPI and other locations and determine which dependency you should even take? You'll learn
all of that and more. You'll go from basically writing scripts and little utilities to building
proper applications by mastering dependency management. Another new course that I wrote is
Using and Mastering Cookie Cutter. If you want to help users fall into the pit of success when they get
started with your project or your library, having a cookie cutter template that sets everything up just
right for them is a really good option. So if you want to learn about cookie cutter, how to consume
it as a user, how to create cookie cutter templates as maybe a project lead or something like that,
and even modify and contribute back or just customize for your own purposes, the cookie cutter project,
then you should check out Using and Mastering Cookie Cutter.
And the final piece of news is we're now offering course bundles. If you come to training.talkpython.fm,
you can buy an entire year's worth of content. So make this year the year you grow as a developer and get a year's worth of Python training guaranteed. Now let's talk to Al and check in on his cat.
Al, welcome to Talk Python.
Oh, it's great to be here.
Yeah, it's great to have you back. It has been a long time since we talked about your huge cat.
Oh, yeah. Yes, she is slightly less huge these days. I put her on a diet.
Your cat's on a diet. How awesome.
Yeah, she's, well, still kind of a bowling ball, but yeah, she's doing great.
I know you were on show, I think it was show 19. I'm just doing that from memory, but certainly around that era. But I suspect many people listening now don't remember the story. So maybe let's talk about how you got into programming and how you got into Python and just start from there.
Well, yeah, I always say that I hate telling people how I got started into programming because I was one of those kids that learned how to program in about the third or fourth grade, just programming in basic, making little computer games.
And I hate telling people this because it sort of reinforces that idea that unless you were programming, you know, from when you were a toddler or something like that, that you'll never catch up and there's too much to learn and you're too old to start learning to program, which is really nonsense.
Yeah, I think everything that I learned about coding from like third grade up to graduating high school when I was like one of those computer kids. I'm pretty sure anybody with, you know, the internet and Google and Stack Overflow can learn everything I learned in like maybe a dozen weekends.
Yeah, maybe just YouTube alone would take care of it.
Yeah, yeah. I mean, learning to program is so much easier today than it was 10 years, 20 years ago. Whenever I say like, oh, I've been programming since I was in the third grade, that's fairly meaningless these days. And so, yeah, I don't want to discourage anybody from learning that. And also whenever anybody says, I've been programming since I was, you know, 10 years old or something like that, I keep thinking, well, yeah, but it was probably pretty lousy programs that you were making.
It's true.
Just like I was.
Yeah, you know, what's really interesting about when you stayed experience in those terms is you could have been working for two years, but on like a massive wide range of technologies and really throwing yourself into it.
Or you could have been programming for 20 years, writing basically the same code. And I would put my bet on that two year person being able to do more in the industry, having that experience. And if you just keep doing the same thing.
So there's quite a lens you have to put on. Like I've been doing it for 20 years or 10 years or whatever, right?
Yes, definitely. And the one constant in this industry is that you're always going to have to be learning new things pretty much nonstop. So the feeling that you're really dumb and you know nothing is never going to really go away. So just get used to it.
Yeah, that was my Saturday morning. Saturday afternoon, I felt a little bit better about life. But Saturday morning, I was like, Oh, gosh, really? Why can't I make this work? This is killing me.
So yeah, it's a never ending thing, which I think is what's wonderful about the programming industry. But if that's not your thing, then you're not going to love it, are you?
Yeah, I mean, certainly a lot of wheels get reinvented. But I think that there is measurable progress being made. I mean, you can just do so much more with software libraries and tools today. And yeah, so I very much encourage people to continue to or just pick up learning how to program. Or maybe if you tried picking it up like a decade ago, and you thought it wasn't for you, just give it another shot.
Yeah, absolutely. You know, one of the things I think is interesting is you talked about how the tools weren't really that great to write software when you got started. And I suspect I'm just assuming but the scope of the things that you created was pretty narrowly focused, right? You weren't like creating YouTube, or Dropbox, or something like that, right?
Right.
I mean, it feels like on one hand, the programming tools and languages have got so much better. And yet there's more programmers, and we still work hard. Like, why do you think that is?
Well, I think it's just the scope of things that we build are so much greater. This for the last couple of weeks, I've been learning bootstrap. And this is a JavaScript and CSS framework for basically creating modern looking websites. You know how websites usually have like the giant image on their front page.
Yeah, and then they have like another row with like three little images in a row. And then they have like another row. And you can sort of tell like, oh, this is sort of a website created with bootstrap. But the reason that all these websites look that way is because bootstrap makes it really easy to make this reactive website that looks great on your desktop, but also great on your mobile phone.
And it's doing a lot of busy work behind the scenes to make that happen. But using bootstrap on the other hand, is really I mean, I'm really impressed by how by how simple and easy it is to pick it to pick up and start using. And meanwhile, it's doing something that if I were to try to do it on my own would just be weeks and weeks and weeks per web page or per site or anything like that.
You'd have to learn about reset CSS is about media queries, about poly fills for different. It's just like, oh, like all that stuff is gone, right? So now we can focus on building something.
The design is kind of solved a little bit. I mean, it's still a challenge. But right. So we would look beyond those problems and say, okay, now what is the actual problem we're trying to solve? Right? And I totally agree that this is.
There's in my opinion, there's no danger that we are going immediately out of a job.
Oh, definitely. I remember, like, I think sometime in the early 2000s, I was in a coffee shop and I was overhearing somebody talking with some software developer and they asked him, like, I don't know, like, do we need more software? Like, when do we like, will we always need more software? And I kind of thought it's sort of like, well, I don't know.
Will we need more novels? Or will we need like more movies? Or, you know, it's like, oh, we already have this detective story. I think that entire genre has been filled by this one book.
So yeah, I mean, in a sense, you know, we're always going to be creating new word processing applications or new instant messaging applications.
But there's a lot of stuff. And I think we just sort of take it for granted and forget that it's there in the same way that fish just forget that water is wet because we get so used to it.
But I mean, like, all these modules like jQuery is what made JavaScript programming so much easier. And even things like Python is just making programming in general so much easier compared to working with C++ or older languages.
A lot of busy work that you would have to do as a programmer writing code in assembly is just taken care of for you so you can concentrate on what makes your application different.
Yeah, come to think of it, I haven't allocated or deleted any memory in quite a while.
Awesome. So people may remember from episode 19. I'm pretty sure that's right. But why don't you tell everyone what you do day to day these days? Like, what do you do for a job in addition to writing books about inventing games?
So I wrote those books and then started self publishing them while I had a full time job as a software developer. And about three years ago, yeah, I think it was 2004 was when I took the plunge and I was in the middle of writing automate the boring stuff.
And I was fairly certain that I was going to be past deadline on that. And I was just everything was was working out well for me at that point where I thought like, okay, I can leave this job and continue writing full time.
And I think automate like, you know, came out later that year or sometime 2005, I believe. But yeah, it worked out that I could finish this book. And if it was really successful, maybe I could continue writing more books. And if it wasn't, then I was in a position where, you know, just being in San Francisco as a software developer, it wouldn't be that difficult for me to get a new job. I'm always blown away by how successful automate the boring stuff has been.
Yeah, that's a great book. And that was the topic of our first episode that we did together. Somebody recommended I reach out to you because they thought your book was so cool. And so maybe tell people, you know, what's the elevator pitch on automate the boring stuff?
So automate the boring stuff is a book that teaches non programmers and office workers how to code and also how to do really practical tasks. So the one story that I think of is I had a friend who worked in an office and part of his job was
just opening up PDF files and then finding this one line in each of these PDF reports and copying and pasting it to an Excel spreadsheet and then just opening the next PDF and just doing this for four or five hours at a time.
And it's something that he taught himself a little bit of Python coding and grabbed a whole bunch of modules like he doesn't know the PDF file format, which is insanely complex, but he can learn how to use this PDF module for Python to grab this text and then update an Excel spreadsheet.
And it took several hours to write this, but running it now, you know, it takes a few seconds to do all that work that normally would take him hours and hours.
And I realized that, you know, a lot of people were saying, oh, everyone should learn how to code.
And I sort of thought, well, what exactly could you do if you weren't a software engineer, but, you know, you do work with a computer every day.
What are the things that you would want to do to using programming to help just free yourself from a lot of tedious tasks?
And so that's sort of the first half of automate the boring stuff with Python is a general Python and programming tutorial for complete beginners.
And the second half just covers a whole bunch of useful modules that the Python community has created.
Right. And just little tasks that you could automate in your life that, you know, maybe you have somehow, right?
Yeah. Oh, yeah. Yeah.
Nice. So I think that's a great idea.
And when I hear people say that we need to teach everyone to code or coding is a core skill like math and reading.
I do feel that that's true, but I don't feel like we need 10 times the programmers.
I feel like instead, like having some sort of programming skill amplifies whatever you actually are good at.
Right. So if you're if you're a biologist, you're going to be a really effective biologist if you can automate things.
Right. If you can use a little Python to like not do stuff by hand and collect a bunch of data and whatnot.
Same for finance, same for whatever. Right.
Oh, yeah. And today, most people who want to gain more technical skills are pretty much doing programming, except they're doing it with Excel.
Essentially, just like creating really complicated spreadsheets to manage large amounts of data and then using these complex formulas.
And, you know, that's a great thing.
And but also a terrible thing because, oh, my God, that code.
But, you know, actually sitting down to learn a programming language like Python makes, you know, doing these tasks so much easier for them and also, you know, produces very readable code.
And it's possible to share this these small scripts with other people.
And also, I guess the same is done with Outlook mail rules.
Like I remember at my at the last job I had, you know, I would get about 150 or 200 automated emails for different things every day.
And it would be completely unmanageable, except I just set up, you know, a dozen or so Outlook rules where, you know, if I get an email from this email address with this in the title, like search for this substring, filter it to this folder and just doing that over and over again.
Well, I mean, that's essentially the nature of programming.
You're trying to program this logical intelligence to do all this tedious work for you.
Yeah, I think that's a great example for people who are getting started.
Right.
I think I have a ton of Gmail rules as well.
Very nice.
So maybe we should start by getting start getting into your book.
So you have a number of books and one of them you just released the fourth edition and it's called Invent Your Own Computer Games with Python.
Right.
Yes.
Yeah, it has an absurdly long title, but it was the first book that I ever wrote.
And I put book in quotes because it was sort of just a series of web pages that I had.
And I just started putting chapter numbers on them eventually and then created a self-published book for it.
So I thought like, I don't know, it's sort of like Invent Your Own Computer Games with Python.
And I didn't realize like, you know, I was like, oh, if I'm going to make this a commercial book, maybe I should come up with a snappier title.
But it became popular.
And so that was sort of the title I was stuck with.
No, I think it's a good title.
It's pretty descriptive.
It's not too long.
So I know not everybody gets into programming because they want to create computer games.
Like I don't feel like I personally got into programming to create computer games.
I was, I came more, I think I came at it a little bit later.
So I came at it from a, hey, I have these research problems in my PhD program I got to work on.
So let's try to solve those or even in undergrad.
But a lot of people do want to build games, especially younger people.
Right.
And so, so what's the audience look like for your, your book?
The current audience, it's actually quite a wide range of readers, but the intended audience is roughly maybe as young as nine years old.
But sort of, I always pictured invent your own computer games with Python as the book that I wish I had read or I had when I was young.
Because I remember there was like only very few books on programming in BASIC that I had access to.
And there were so many different versions of BASIC that, you know, some of the programs didn't work and I really didn't have, there was no real internet to Google for answers.
So I wanted to just get a broad range of different types of games.
And so that's why the, the book ended up with over 20 chapters of, of games in it.
Yeah.
I think that's really cool.
Yeah, it was just, I wanted a book that went from knowing absolutely nothing to being able to make some like really like clever little games that wouldn't take up that much time.
You know, it wouldn't take like a week to write.
Games are a great sort of gateway into the world of programming.
Like I, I really didn't have that many ambitions of becoming a professional game developer, but learning how to program games just because I was really into Nintendo as a kid became this, it was the main motivating force for me to get into programming.
And then later on become a software developer.
Yeah, it's cool.
And each little chapter is pretty small and everyone has a different game or most of them have different games where there's kind of a quick win.
And I think when you're learning programming, that's so important because you can spend all your time going, here's how you declare variables.
This is what a type is.
This thing is an integer.
That thing is a string.
This is a loop.
This is the function use the def word, but you think it's like, oh my gosh, like why do I care about this anymore?
I thought this would be fun and it's not fun anymore.
Right.
So how do you solve that?
Do you think, like, how did you address that at least in your, your book?
So in my book, and I really am copying what a lot of like bite magazine from the eighties, which would have just listings of source codes of source code for a small game.
That you would just copy from the magazine.
There were also a lot of.
Maybe even type it in, right?
Yeah, yeah, exactly.
And I believe, Atari archive.net or Atari, Atari archive.com is a website that has a lot of these old basic programming books that you can view online now.
And I thought it was just great because none of the programming books that taught me like, these are variables, these are loops and everything.
Like I had the reference manual, but that didn't show me anything.
I couldn't make heads or tails of it.
But I found one book that basically taught by showing the complete source code to a small game and then just sort of explaining how it works.
And as I was writing, invent your own computer games, I realized with Python, if anything, this is way easier than with basic because the code is much more direct and much more simple than having to, you know, sort of, there's still a lot of hoops that you would have to jump through through basic, even though basic was revolutionary for its time as being a simple programming language.
Right.
Still, it didn't have much of a base library that you could leverage.
There's a lot of stuff you had to do yourself, right?
Yeah.
Nice.
So you start out in this thing by explaining a couple of pieces, like what is the REPL?
What is the interactive shell?
How do you write programs?
What is a variable?
It's interesting.
When I started doing training for software developers, I always, my first concern was I'd end up in a classroom of super smart people and they would ask me all these hard questions and I would not know the answer.
And I would look stupid or they would feel like they didn't get their money's worth or whatever.
What I found was those people are super easy to talk to because you are speaking the same language.
But when you are speaking to somebody who's just getting into programming, like many of the people reading a book, that is a much harder conversation in my mind.
And I think you did a pretty good job.
But like even talking about what is a variable and how does code execute?
I think it's easy to just go, well, it just does.
You just run it or whatever.
Right.
Like, like, was it easy for you to explain that stuff in a way that you felt conveyed it to newcomers?
I mean, I think my main approach to that was just for, I would write out sort of a map of all the topics that I wanted to cover and then just start drawing lines between them saying, like, in order to understand this, they have to understand this other concept and in order to understand that.
So I would sort of get this dependency graph of concepts.
And a lot of times I really am just sort of tempted to just say, like, well, it just works like this.
But the great thing about Python's interactive shell with the REPL is you kind of can get away with saying, well, this is just how it works by showing an example in the interactive shell.
Like, oh, type this in and then it spits this out.
And it's surprising how just having this sort of visible example that they can see and then you can show, like, oh, you can type, like, 2 plus 2.
And then you can also type 2 plus 2 plus 2 and then just sort of explain that, like, well, 2 is just a value.
Like, this is kind of like math problems in your math class, except if you think of these numbers as values and those plus signs as operators, you can see that this is an expression which just combines those and evaluates them down to, like, a single value like 6.
But I really lean heavily on the interactive shell for just demonstrating this because the last thing I want to do is just sort of talk about these concepts instead of actually showing, you know, what the computer does when you type in these instructions.
Yeah, that's the best way, right?
Is you have to just do the thing if you want to learn programming.
It's kind of unique in that sense.
I guess math.
If you're trying to learn advanced math, you can't just read a bunch of math and then, like, be able to solve problems.
You probably got to just do it as well.
But it's certainly one of the disciplines where you have to sit down and do the thing and experience.
So the REPL seems like a great way to do that.
Yeah, I mean, the great thing about computers is they do exactly what you tell them to, and that's also one of the worst things about them.
The most frustrating things ever.
It is much nicer to learn how to program, you know, with the computer right there in front of you telling you when you get things wrong as opposed to, I don't know, if you just checked out a calculus book from the library and tried to learn calculus.
I mean, you have this sort of inert book sitting in front of you, and maybe you're doing the math right, maybe not.
It's hard to tell because, you know, maybe you have just the answers in the back of the book for the questions in the math book, but you don't have, whereas the Python interactive shell, it'll always be able to tell you, like, oh, this evaluates to that or this raises such and such exception.
Yeah, exactly.
The only one that's hard to get it to give you an answer is infinite loop.
Oh, yeah.
Well, you know, you just have to wait a while.
Exactly.
I'm just going to wait for a little more time.
So one of the things that you used in the book was Idle, the graphical tool that comes with Python.
Why did you pick that over some other tool?
Like, I know the book was written a little while ago, so maybe those were some of the better UI tools, or what was the story there?
Oh, I wouldn't say that.
So Idle has, I would say, two things going for it.
I mean, it is sort of like a very rough IDE, and it's more text editor than IDE.
But the great thing about it is that it's really simple.
You can just fire it up, and it has the interactive shell in one window, and it has a file editor in another window.
And you can just press F5 to run your program, and it's really easy to get started with.
And then the second thing is also that it comes with Python.
There's nothing extra that you have to install.
You don't have to configure any environment variables.
You don't have to navigate your file system to find the, you know, Python.exe or the Python interpreter.
And this is actually a pretty big deal, especially if you've ever had to teach Python or teach programming in a classroom setting,
where now you have 15, 20 laptops that you have to set up, and maybe you don't have all the permissions
because the school district or the IT department decided to lock down all the permissions on things.
It just saved me a whole lot of steps where I wouldn't have to talk about, like, here's how to install Notepad++ if you're on Windows.
But if you're on Mac, then here's how to install PyCharm, and here's how to set it up, and all these other steps.
And I really feel like Idle is one of the reasons why Python...
I mean, there's lots of reasons why Python is so popular, but Idle is certainly one of them.
It makes Python a language that's easy to get started with.
And the more of that you have for any language, the more adoption you're going to see,
and the bigger of a community that you're going to create.
Yeah, I see.
So it's in your Start menu, it's in your Applications folder, or whatever, right?
And it's...
Once you run it, the path is there, right?
It's not like this environment variable is not set up, or whatever.
Okay, that's a pretty good reason, actually.
We all love Python for its tremendous productivity benefits, but getting the best performance takes some work.
What if you could get out-of-the-box, easy access to high-performance Python?
Intel Distribution for Python developers delivers just that.
Get close to 100 times better performance for certain functions when using NumPy, SciPy, Scikit-learn,
linked with optimized native libraries like Intel Math Kernel Library,
access-efficient multithreading, and Python projects like Numba and Scithon.
Try the Intel Distribution for Python and experience performance today at talkpython.fm/intel.
And profile your Python and native C, C++ applications for performance hotspots with Intel VTune Amplifier.
With Intel, it's all about performance.
Do you think that Python would be better off if it had something like Swift Playgrounds?
Do you think that matters?
Oh, like what?
Like Swift Playgrounds.
Are you familiar with those?
Oh, no.
No, I'm not.
So, Swift Playgrounds, basically, it's kind of like a REPL, but on the right-hand side,
you can have, like, graphs and little animations.
Oh, okay.
And you've got the code, like, on the left and on the right, the output of that code going down together.
Interesting.
I think, like, IPython Notebook is sort of similar to that.
Like, it can have non-text output.
Yeah, IPython is the closest I can think to it.
But, you know, IPython is not something that's super easy for beginners to set up.
Like, tell somebody, like, you have Python, now get IPython running on Windows.
You know?
Right.
Yeah.
Well, the problem is I can't find vcvars.bat or whatever that thing is, right?
Oh, vcvars.bat.
Yeah.
You're like, oh, okay.
Forget it.
I don't know.
I'm just, I feel like there's Idle, and if, like, Idle was taken to the next level, it would look a lot like Swift Playgrounds.
And I'm wondering if something easy and built in there was really, really slick.
Whereas it feels like it's effective and it's nice, but it's not really slick these days.
Yeah.
Well, I mean, Idle is definitely sort of showing its age.
But in a certain sense, it is fairly timeless where it just has the, its simplicity means it can get away with just having the interactive shell and the file editor.
And it's perfect to work with.
It is also, I guess, somewhat controversial to just sort of add an application with your programming language.
But I'm really, or even something like a GUI toolkit like TKinter that was added to the Python standard library.
I don't really know of any other programming languages that sort of do that with their standard library.
But I'm certainly glad that that happened, that ended up happening.
Yeah, it was definitely nice for your game, right?
Yeah.
For your game book.
Oh, yeah, definitely.
Nice.
So you want to touch on some of the games that you take people through?
I mean, obviously, you have the requisite guess a number high-low game to start.
Yes.
I mean, that's, that's something that I've seen over and over and over again.
Even when I was back first writing this book, I felt like, okay, guess the number is perfect.
It has loops and if-else and variables.
And it's also just kind of like a fun little game where, you know, you can say like, oh, 10.
Well, my number is higher than that.
And so you can sort of do this dictionary style.
Yeah.
Binary search.
Sorry.
Yeah.
Yeah, exactly.
Yeah.
You're unwittingly, like the optimal strategy is the binary search for humans.
I do feel like that's one of the games that is like on a per line of code, like is the most dense in like fun and joy, right?
It's like what, like eight, nine lines of code probably.
Oh, yeah.
And people can actually get some anticipation and something out of it, which is pretty cool.
Yeah.
And so the book, that's the first program in the book and it continues on with, there's like a little joke telling program.
I mean, so there's not all the chapters have game programs.
Some of them are just sort of like fun little programs to run.
There's this joke telling program, which is really there just to get familiar with how to output text in certain ways and format the text.
And then next is a game called Dragon Realm, which sounds really fancy.
But actually, if anything, it's even simpler than the, I guess, the number game.
Is that like a mud?
Oh, well, I mean, it would look like it, but really it comes down to pick cave one or cave two.
And then it tells you if a dragon has eaten you or not.
Yeah, it's like one step in a mud.
Yeah, it's a coin flip, but it has like a really nice user experience tied around and story behind that.
Kind of like a lot of modern games where as long as you have a great story, we don't care if the game itself is kind of dull.
Yeah, exactly.
Exactly.
Yeah, I like the retro game experience where they specifically sort of water down the graphics and make it about the game experience and the story.
And it's kind of nice not to have like always the most shiny, shadowy, reflected on water graphic engine.
Right.
With nothing else to it, you know.
I definitely grew up with muds and sort of text adventures and that style of games.
And invent your own computer games with Python similarly has just text based programs for I think the first major chunk of the book in the last four chapters starts covering Pygame and 2D graphics.
But the great thing about having text only for just, you know, having keyboard input from the user and then all the output is just print statements is that you can always tell from the output that you get from the program where that came from in the source code.
So you can sort of like draw a line like, oh, okay, this text here that says the dragon ate me comes from this line, which is print the dragon ate you.
And so you can actually sort of see the flow control going through the program.
Whereas, you know, a lot of I don't know if you like fire up Unity 3D or something like that or just these really complicated game engines.
It's kind of hard to figure out what part of the code causes what to happen on the screen.
Oh, yeah.
Those 3D versions get so, so intense.
I remember I had done a 3D simulator in OpenGL and I couldn't see the thing that I was trying to display on the screen.
I'm like, I know it is in front of me.
Why can't I see it?
And I had like back face culling turned on and I had gotten clockwise versus counterclockwise backwards.
Oh, right.
So it thought I was inside the thing and it just took it.
I guess it was and it took me, I remember hours of like, why can't I see it?
And it should be counterclockwise, not clockwise.
It doesn't.
It only draws one side of the triangle that you're looking at.
So if you look at it from the other side, it disappears.
Exactly.
Why am I looking at the inside of this, not the outside of it?
Yeah.
So it certainly, I don't think that's a good place to start, even though like people, many people where I think, oh, I'm going to create Eve online.
I'm going to create some kind of unreal thing.
It's effective, but it's also not so, I don't know.
It's not as much fun as it sounds like in the end, in my estimation.
Yeah.
I mean, actually, so I'm working on a book right now for No Starch Press because I do some teaching classes with kids and they say like, I want to program Minecraft.
Minecraft is like the main game that I hear over and over again.
And I'm just like, oh, yeah, well, that's going to be a lot of work.
But the next book that I'm writing, which so far doesn't have a title, but I'm roughly calling it Programming Robots in Minecraft, is a book that covers this one mod for Minecraft called Computer Craft that adds in these programmable robots into the game world.
And so you can write these Lua scripts to program these robots.
And they're called turtles, just like the old logo turtles that do drawing on the screen.
So you can program these robots to just like move forward, move, you know, turn left, move forward again, start mining in front of you.
And you can basically have these robots sort of do all of your mining or chopping down trees or tending to a farm or building for you.
I jokingly call this book Automate the Minecraft Stuff with Lua.
And so I was hoping like to use this, getting kids who are really interested in Minecraft into programming, once again, using games as sort of a gateway into that.
The broader world.
Yeah, absolutely.
Yeah.
I'm just really sad that it's all in Lua instead of using Python.
But Lua is also.
Is there some sort of, yeah, is there some sort of Python adapter you could do?
There is a Python module.
In fact, I think NoStarchPress has a book called Learn to Program with Minecraft that uses a Python module for Minecraft.
It's more like a sort of a 3D editor.
Right.
Using in the Minecraft world.
So you can specify like XYZ coordinates and then change that block to something else.
But it's great because now you can just sort of instantly build giant creations by writing code.
Sort of like, you know, computer generated art.
Yeah.
You have these computer generated blocks now.
Okay.
Very cool.
Have you seen the movie Indie Game?
I-N-D-I-E?
Indie Game?
No, I haven't.
And there's Indie Game and then there's like a sequel.
And I think it's on Netflix and other places.
But it follows these four or five groups along who spend like a couple years doing just solo Indie Game development.
And either they're a great success or not so much at the end.
And it's, yeah, for people who are interested in this kind of stuff,
that might be a good movie recommendation.
Oh, yeah, definitely.
I mean, I keep thinking like, I hear about Minecraft and Dwarf Fortress and a game that I recently got into, Stardew Valley.
And these are all created by sort of like solo or just like very small teams of people, usually one person, just over years.
And there were just these big labors of love that turned into this great thing.
And I was thinking like, oh, man, I could totally just spend the next four years of my life just sitting in a small room.
And I'll program something that's like a cross between Stardew Valley and Minecraft.
And I'd call it StarCraft.
There's no trademarks or anything.
It'll be great.
Nice.
Yeah.
I saw one of the guys that was on there.
He was featured on the Apple App Store with his sequel game.
So he must have gone somewhere with that.
That's cool.
Yeah.
So that's great.
So what other games do we have?
We have Hangman, of course.
Yes.
And this game actually is sort of like the first major game in the book.
I've actually spread it across a couple chapters.
And I also talk about how you should write out flow charts for sort of designing what you want your program to do and how, you know, it's a lot easier to just change a flow chart around than it is to actually start changing code around if you later, like, come up with a better idea or something else like that.
So just doing a little design ahead of time and thinking about code before you start writing it.
Yeah.
You probably wouldn't do that too much as a professional developer these days.
But certainly when the concept of, you know, what is a function again?
Right.
When you're at that level, it does become hard to manipulate the code and whatnot.
So having it drawn out is nice.
Yeah.
And also it's just a flow chart is just sort of a natural way of depicting the flow of execution through a program.
Nice.
Okay.
So tic-tac-toe, does it play against you automatically?
How do you play tic-tac-toe?
Tic-tac-toe.
So this is a tic-tac-toe game against the computer and the computer is actually somewhat intelligent.
So it'll look, if it can win the game by making a move, it'll make that move.
And then it'll check if it can make a move that will block the player from winning the game, it'll make that move.
And then I think the algorithm goes on where it'll take any corner space that's free and then any side space that's free.
Or I think maybe it takes the center first.
But I really wanted to introduce the idea of you can actually have, you know, again, it's still just a bunch of function calls and if-else statements.
And sort of also the first time where I introduce a data structure, we have a data structure to represent the tic-tac-toe board.
And this data structure is what's used by a bunch of the functions to sort of plan out what the AI will do.
I remember trying to program this as a kid in BASIC by following some source code that I was copying and I could never get it to work.
I would just like try it and then like a couple weeks, you know, forget about it and a couple weeks later I would try it again and it would just never actually work out.
And so when I was writing this originally for the, I guess, seven years ago I think was when I first started writing this book.
It was kind of like a miniature triumph that I got the tic-tac-toe program working.
You will not haunt me anymore, tic-tac-toe.
We're done.
Yes.
I have produced my masterpiece right here.
Yeah, that's awesome.
But yeah, and the game continues on.
I have like a few other games.
There's like a deduction game called Bagels.
It's also called Mastermind where it's sort of your, it has three numbers and it tells you guess which numbers and it gives you clues where like if you've guessed one digit or if you've guessed a digit but it's in the wrong place.
That sort of deduction game.
And then I also have a small chapter on the, on a little encryption cipher program so that you can do the Caesar cipher cipher, whereas, which is where you shift the letter over by three characters.
So like an A becomes a D and a B becomes an E and then you decrypt it by just shifting the letters back.
But this was just like a really simple sort of like encryption program that you could make in Python.
It's not necessarily a game.
I thought it would just be like a really fun thing.
This episode is brought to you by GetStream.
If you're building an application that has some form of activity stream like you might see in Slack or Facebook or Instagram and others, then you owe it to yourself to have a look at GetStream.
They provide scalable, reliable, and personalizable hosted API feeds as a service.
The feed is the most intensive component of these types of applications.
Yet there's no need for you to reinvent the underlying feed technology when GetStream has the infrastructure and a Python API already in place.
Go from zero to scalable feed in hours, not weeks or months.
They even use advanced machine learning to serve up personalized results to each and every user.
Stream powers the feeds for over 500 companies including Makerspace and Fabric with a total of 70 million end users.
Try the API yourself in a short five-minute interactive tutorial at talkpython.fm/stream.
Try it for yourself.
It helps support the show.
Actually, this chapter sort of inspired me to go on later and I wrote an entire book full of these.
in hacking secret ciphers with Python.
Nice.
Yeah, I think ciphers are another thing that are pretty fascinating to people.
It's a parallel track to being interested in games.
These secrets and these secret ciphers are quite interesting.
Encryption is so complicated these days that it's not fun to look at anymore, but trying to solve things.
Especially when one minor oversight means that your entire system can fall apart.
Yeah.
Yes.
So I wrote an entire book of bad encryption in a modern sense.
They're terrible ciphers.
But these are all sort of like classical ciphers.
Caesar cipher literally goes back to the times of Caesar.
Was Caesar actually using it?
Yes.
So this was sort of the system where they would just shift letters over by three characters in the alphabet.
And that was how they would encrypt things.
Of course, back then, just writing things down was effectively encrypting things because most people were illiterate.
But, you know, just the idea of you're just seemingly writing a bunch of nonsense onto writing that down.
And then that, you know, anybody who intercepts that message would just be completely confounded because these concepts of encryption and, you know, treating letters as sort of generic symbols that can be manipulated according to some algorithm.
That just wasn't really common.
All that common.
So, I mean, the Caesar cipher was very effective.
Yeah.
I mean, it just seems like so basic.
And it's, you know, encryption for like a serious empire.
Right?
Yeah.
I mean, and so there are basically a few other different cipher schemes that came up.
But really, I think it was the visionier cipher.
I'm never certain if I'm pronouncing that correctly.
And it's really the visionier cipher is sort of like the Caesar cipher, except slightly more complicated.
And you have a different key for the first letter of, you know, if you have a key that's four letters long, then you have one Caesar cipher key for the first letter of a message.
And the second letter, you have a second key in the third letter.
You have a third key in fourth letter.
You have a fourth key in the fifth letter.
You go back to the first key.
And this was really kind of brain dead simple, but it remained effectively unbreakable.
They called it the indecipherable cipher in French, which I'm not even going to attempt to pronounce.
But I think Charles Babbage solved it, but never published or was able to break these messages, but never published his method behind that.
That's like back to the 1800s or something, right?
Oh, yeah.
Yeah.
I think it came about in like the 16th century or so, I want to say.
But for, you know, a couple hundred years, it was just unbreakable.
But, you know, these days, like anybody with a laptop and a little bit of programming knowledge could write something that can just do all the number crunching that you have to do to come up with to be able to break these ciphers.
So I wanted to sort of write an entire book on that.
Oh, yeah.
And so all of these Python books, you know, going from Invent Your Own Computer Games with Python, even the fourth edition and Automate the Boring Stuff and Hacking Secret Ciphers, I released under a Creative Commons license.
So you can find them online at inventwithpython.com and they've been copied to other sites, I'm sure.
I just really wanted to put this information out there and get it into the hands of as many people as possible.
Yeah, that's great.
And so people can go check it out and they can basically read it online there, right?
Or they can buy the tree version or maybe even a Kindle version, huh?
Yeah, yeah.
And the Kindle version is slightly, it's formatted much, much more nicely.
I just sort of have these HTML versions that I sort of hastily exported from Word.
But, you know, so all the information is there, even if you don't have the funds to pay for an actual like dead tree book.
And I get a lot of emails from sort of students and other people who are, you know, really thankful that information is there, that they can just read it off of their screen without having to buy a book.
Yeah, yeah.
That's really cool.
Do you know if your book is being used in any like classes, like official classes?
I do get some emails from a few teachers who say they're using sort of like invent with invent your own computer games with Python as part of a class.
I never really wrote it sort of to follow a curriculum or to be teachable, you know, in 45 minute or 90 minute class period.
But, you know, I'm really glad that, you know, it has some examples that they can pull out, especially being online and under a Creative Commons license where they can easily just copy and paste the sections they need and print it out as needed.
So I'm really glad that it's just produced some material that teachers can make use of.
Yeah, that must be really cool to think that there's probably kids out there learning through your book.
And also really terrifying, just in case I have any typos or weird practices of mine.
I should have actually made that more clear how this works.
Don't actually do this for real people.
So you kind of wrap up things by talking about Pygame and you even have another book on Pygame itself, right?
Right.
So Pygame is a 2D graphics library.
It's Pygame's really a wrapper for another library called SDL that is very popular with programming 2D stuff with C++.
But Pygame really makes creating sort of graphical games so much easier.
You can just sort of point to a PNG image file on your hard drive and then just display it in a window and then start moving it around.
And it can support mouse input and also play media files.
You can play MP3s or WAV audio.
And I once wrote a blog post a long time ago about professional games that actually make use of Pygame.
I know that there's at least two or three of them that are on Steam, the PC game marketplace, that were originally just created in Pygame.
So Pygame is mostly seen as sort of a, you know, just sort of like a toy hobbyist library, but you can actually make commercial games with it.
That's really cool.
Yeah.
So a good 2D scroller might work well there, huh?
Oh, yeah, definitely.
Nice.
Yeah.
So at the end of Invent Your Own Computer Games with Python, I had a few chapters devoted to sort of just a very light introduction to Pygame, followed by one game programmed using Pygame.
And I thought like, wow, I have a lot of other ideas for small games that I'd like to create.
So I thought like, well, I guess I'm writing another book.
And yeah, and so it was that was the second book that I wrote.
It was also self-published.
And then Hacking Secret Ciphers was self-published.
And this was all, you know, just a spare time hobby of mine.
But it was sort of this was what built up my confidence into thinking like, hey, OK, I have an idea for a book that could be really, you know, possibly really popular that I would want professionally published.
And that's sort of when I approached No Starch Press about publishing Automate the Boring Stuff with Python.
That's really cool.
Was it weird?
Like, when did you first start describing yourself as an author to other people?
When they go, hey, what do you do?
Like, I'm a programmer.
Leave me alone.
It's always been weird because I thought like, well, you know, it's just a self-published book is what I would always tell people.
I guess it was really sort of with, you know, Automate the Boring Stuff.
You know, I would go to Python meetups and people would know who I am because of that book.
Or I would go to PyCon and people would have heard of me.
And it's a strange feeling that never quite stopped being strange.
Yeah.
But, you know, it's also a great feeling.
I remember I came over to see you at the No Starch Press booth last year at PyCon.
And that's how I found you.
Yes.
At PyCon.
Hang around with the books.
Right on.
Yeah.
I remember at that PyCon, I had two people who wanted to take selfies with me.
And so I kind of felt like a rock star.
And it's, you know, I mean, our industry talks a lot about imposter syndrome.
But I feel like I have enough experience under my belt right now that I still feel like an imposter.
But I'm pretty sure I'll get away with it for the rest of my life.
You've pulled it off for enough years that you think that the trail's gone cold.
I am completely confident in myself that no one will ever find out what a fraud programmer I really am.
Nice.
So speaking of the trail, what books are you working on next?
So, yeah.
So I have the Minecraft book that I'm working on.
And I keep coming up with ideas for, I don't know, like automate the boring stuff with JavaScript.
Or maybe sort of a SQL to automate where you're using Flask to create really small applications.
So, and again, this would be sort of for office workers who have something that they, you know,
some custom software that they would like to have written that's really small,
but they don't want to hire, they don't want to like contract out a programmer to write it for them.
I was thinking like, well, you know, you could actually use Flask in the browser for all the UI components and everything like that.
And I thought like, okay, that would be pretty good.
And then I just keep poking around with other ideas.
So, but for right now, the Minecraft book is the one I'm working on.
And I'm also creating a website that is set up so that readers of that Minecraft book can then go on and write their own programs for Minecraft robots.
And then go to this website to share their programs with a lot of people.
I use this tool called Scratch from MIT in a lot of teaching to programming to kids.
It's a great system.
It's has sort of this like snap together block interface for creating games.
I really like it.
I used it for my youngest daughter's hour of code.
I went in hour code in like elementary school for all the grades, eat one grade at a time.
And we used it and I was blown away at how good the kids could do stuff with it.
Oh, yeah.
I mean, the one thing that I've learned is that especially young kids really have problems typing or, you know, they're just like pecking at the keyboard one key at a time.
And it's really frustrating to type that slowly and then realize you left out a semicolon and now you get some weird error message.
And Scratch fixes that with this snap together block system where it becomes literally impossible to make a syntax error in your code because the blocks just don't fit that way.
And I just, you know, the more I used it, the more like clever design decisions I realized they had made behind the scenes.
And the other great thing about Scratch is not only did they really nail down the editor, but the Scratch, Scratch runs in a web browser.
And also it has a website where you can share all of your programs with other people and also view the source code of other people's programs.
So, you know, if you find some game that's really clever, you know, you have the motivation that you want to create something cool to show off to people.
And learn more programming to do that.
But also if you find a really cool game, then you can just, you know, click on one button and it'll show you the source code behind that.
And that's sort of something I had been thinking about, like, okay, I really want to create a website like that for this Minecraft robot programming book.
And also I've been sort of thinking like, oh, maybe I could create something like that for Pygame specific games as well.
That would be really, yeah, that'd be really fun.
Yeah.
You could, you could totally do that.
A little bit of Docker, a little bit of GitHub.
Yeah.
Exactly.
I mean, yeah.
So, you know, and hence why I'm teaching myself like Bootstrap and a whole bunch of other web frameworks and things like that.
Of course.
I like Bootstrap.
I use it for all my sites as well.
It's great.
All right.
Well, so you're working on the Lua book.
You've got the website coming.
Like, how do people keep up with this?
Like, how will they know when this comes out?
Probably the best way is to probably follow me on Twitter, actually.
But then also I have, I'm restarting, I had a blog on inventwithpython.com that I used to post little tutorials to, and I'm ramping that back up again.
So it's, if you just go to inventwithpython.com and then click on the link to the blog, that's probably like the best way to keep up with what I'm doing.
And I also have, oh, I also have alswigert.com, which is a really plain looking website.
But I kept losing track of like, oh, yeah, I created this Udemy course for Automate the Boring Stuff.
In fact, I think I forgot to mention that in this podcast.
Yeah, yeah.
So why don't you tell people about it?
Because you do have a pretty popular course on Udemy, right?
Yeah.
Around your book.
Yeah.
So this was like shortly after Automate the Boring Stuff came out.
And I kept thinking of like, how can I help promote this book?
And so I found Udemy.com.
So there's a lot of these websites online that have video courses, but most of them you have to be affiliated with a university.
I think like Coursera or edX, you have to be a professor, essentially.
Udemy.com has courses that can be created by anybody.
And so, of course, you know, it does have sort of like a lot of really low quality courses on it.
But I thought like, well, okay, I can try this out.
And so I started making screencast tutorials, basically following along with Automate the Boring Stuff.
And that course actually sort of is the other half of my income.
I mean, it's sort of making as much as Automate the Boring Stuff the book.
And I'm really just blown away by, you know, like, well, okay, I can actually, you know, it wasn't entirely dumb to quit your job as a software developer and enter the lucrative world of, you know, books.
Yeah, I think the trick or the thing you got right is you've got the book, you've got the website, you've got the course.
It's like you sort of got a package around it.
It's not just like, oh, here's a book I did.
Go forth and like live in the world book.
You've got the promotional angles and the different stuff going.
Yeah.
I try to just create a whole bunch of things that sort of support each other.
And, you know, and of course, all of this is just only possible because so many people in the Python community are so excellent about spending their time and skills making Python even better and just building the community.
It's something that I really haven't seen anything close in other programming communities.
So the Python and also PyCon, the Python conference, they just blow my mind.
It's really great.
Yeah.
I definitely second that.
And for people who don't have your PyCon ticket yet, better hurry.
It's going to be sold out and you're going to be sad, right?
I have a booth there with the podcast booth.
And are you going to be there?
Oh, yeah, definitely.
Definitely.
Yeah.
It's not that far from San Francisco to Portland, right?
Oh, yeah.
Not at all.
In fact, last year it was also in Portland.
They do it in the same city for two years before switching.
And I went up with a bunch of people on Amtrak.
So there was a group of people starting in San Jose, making their way up the coast, taking a train to PyCon.
So that was a lot of fun, just hanging out with conference goers beforehand.
I think it was called PyCon on a train or something like that, or Pythons on a train.
But yeah, you can probably, if you're interested in finding out about that, you can probably Google for that.
Oh, that's awesome.
It's about a 15-minute drive from my house to PyCon this year.
So no trains for me.
Oh, right.
Yes.
But maybe sometime soon I'll get a chance, although probably not to Ohio next year.
Right, right.
But definitely, if you guys are interested in going to PyCon and want to do a selfie with Al,
you've got to get yourself there.
All right, man, that's awesome.
So it sounds like you have a lot of cool stuff brewing.
And this book is really interesting.
And thanks for chatting through it with me.
Yeah, thanks for having me.
You bet.
Before I let you out here, two more questions.
We just passed over 100,000 packages on PyPI.
What one of those few would you like to recommend that people check out they maybe don't know about?
Well, if I want to be totally selfish, PyAutoGUI, because it's a package that I wrote.
It's a GUI automation package where essentially you can have your Python scripts control the keyboard and mouse.
So if you just have some task where you need to like click on something over and over again or just like automatically fill out a form and type something for you, you can use this to essentially sort of like simulate having an intern type and click for you.
But I think really I'm really impressed by the requests module.
So requests is a really simple to use sort of version of what URL lib in the Python standard library does for making HTTP requests.
Except requests just makes it so easy to just download files or access websites.
And I'm just really impressed by it.
And so I highly recommend that.
Yeah, I definitely second that.
It's a very, very nice one.
Awesome.
And favorite editor, Idle?
I mean, these days I'm mostly using Sublime Text.
So I've kind of gone the text editor route rather than having like a full-blown IDE.
So yeah, I think I would go with Sublime Text.
But, you know, I guess Idle technically counts as an IDE.
So I would say my favorite IDE is Idle.
Oh, right on.
All right.
So it's been great to chat with you about this.
Final call to action.
What should people do to learn more about what you're up to?
Oh, well, I guess like alswigert.com has just links to,
everything I've done.
But really, like as far as a call to action, definitely get involved with your local Python
community.
If you live in a large city, there's bound to be like a meetup.com group for Python.
Or definitely think about heading out to PyCon, even if you're still a beginner in Python
or, you know, you're not yet a professional software developer.
It's such a great and welcoming community that I really recommend it for a lot of people.
All right.
I totally agree.
Great recommendation.
Al, thanks for being on the show.
Chat with you later.
Yeah.
Take care.
Bye.
This has been another episode of Talk Python to Me.
Today's guest has been Al Swigert.
And this episode has been sponsored by Intel and GetStream.
The Intel distribution for Python delivers the high-performance Intel C libraries built right
into Python.
Get close to 100 times better performance for certain functions when using NumPy, SciPy, and
Scikit-learn.
Check them out at talkpython.fm/intel.
If you're building an app with a feed, make sure to check out GetStream at talkpython.fm
slash stream.
They have the intelligent, scalable, and tested feed API you need to be one step closer to
launching your app.
Are you or your colleagues trying to learn Python?
Well, be sure to visit training.talkpython.fm.
We now have year-long course bundles and a couple of new classes released just this week.
Have a look around.
I'm sure you'll find a class you'll enjoy.
Be sure to subscribe to the show.
Open your favorite podcatcher and search for Python.
We should be right at the top.
You can also find the iTunes feed at /itunes, Google Play feed at /play, and
direct RSS feed at /rss on talkpython.fm.
Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
Corey just recently started selling his tracks on iTunes, so I recommend you check it out at
talkpython.fm/music.
You can browse his tracks he has for sale on iTunes and listen to the full-length version of the
theme song.
This is your host, Michael Kennedy.
Thanks so much for listening.
I really appreciate it.
Smix, let's get out of here.
spinner preview,
back to who rocked the best.
I'm first developers.
Developers, developers, developers, developers, developers.
you