Transcript #242: from lib import * but less
Return to episode page view on github00:00 Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
00:04 This is episode 242, recorded July 14th, 2021. I'm Michael Kennedy.
00:11 And I'm Brian Arquette.
00:12 Hi, and I'm Al Swigert.
00:13 Hey, Al. Welcome. Welcome. Before we get to introduction with you, I just want to say this is brought to you by our courses over at Talk Python Training and Brian's book. But first, let's just hear about you, Al. Tell people who you are if they don't know.
00:27 Hey, I'm Al Sweigart. I'm mostly known as the author of Automate the Boring Stuff with Python and a bunch of other Python and programming books for beginners. So all my books are released under a Creative Commons license, so it's free to download and share them. You can get them at inventwithpython.com. Nice. Yeah, yeah, fantastic. I would say the Automate the Boring Stuff has certainly been well received. Yeah, definitely. I hear it quoted a lot, for sure. Brian, - Yeah. - You just wanna get us started or what?
00:56 - Yeah, I'll just get us started.
00:58 So, no, so just, I saw a tweet by Jeff Triplett that mentioned just, and as a replacement for make.
01:07 So I needed to check it out.
01:09 So, and it's like super cool.
01:10 - Make for the people who don't know is a thing that you can type, basically you type make, and then it automates a bunch of commands.
01:16 Like if you've got a seriously complicated build link process it could be embedded into a make file, and then you just type make and that happens, right?
01:23 >> Right. I don't know what the history of Make really is, but I used it a long time.
01:29 I've been using it for decades.
01:31 One of the things it does well is convert.
01:34 If you've got, take all your.c files and convert them to.o files and then combine your.o files, all the build process for the C toolchain.
01:44 But you can really do it with any language.
01:47 But people have abused it and so have I, even Python projects that often use Make files.
01:53 because make is often around on Unix-like environments.
01:57 Having makefile around, you can use it just to automate some of your common tasks, like make release or something, to do all the commands you need to do to do a new release of a project or something.
02:10 But there's problems with it.
02:12 Just is a replacement for it.
02:16 It's written in Rust, so it's pretty fast and clean.
02:22 Well, actually, I don't know if it's clean.
02:23 I haven't looked at the source code, but it's really easy to use.
02:27 >> It's not C, it's got to be better.
02:29 >> It's kind of looks like main files.
02:32 I went ahead and installed it both on a Mac and Windows today to try it out.
02:37 One of the things I really love about it is, it's not the main part of it is to try to automate commands.
02:44 It's not about, you can build, you can use it to build things and have recipes to make all your .c files into .o files if you want.
02:54 But the real power is to use it in the way we've been abusing make before because you can do some cool things.
03:01 One of the problems with make always has been the recipes have to be defined on the left column, leftmost column, and then you have to have a tab for the commands.
03:17 >> Well, I mean, often I have my editor set up, except for make files to replace tabs with spaces, just works just fine with spaces. I love that.
03:29 Also, you can pass arguments to commands, command lines, stuff like that.
03:35 >> That's cool.
03:36 >> It's super cool. One of the neat things, I don't know where it is in the documentation here.
03:42 You can use arbitrary languages.
03:45 You can even do like a Python command within the just file.
03:50 >> That's cool.
03:51 >> You can do some neat things.
03:53 >> For people listening, you basically declare the languages you want to use, and then you can implement code like print or console.log for JavaScript or whatever.
04:04 >> Right. This actually seems like a bad example because it's actually listing the recipe name as the language name, and you don't have to do that.
04:11 This Python here could just be foo or something.
04:14 Oh, I see.
04:15 So the thing that's important is the shebang.
04:18 Yep.
04:18 The shebang, tells, tells, just which language to use.
04:23 So this is pretty neat.
04:25 I I've started using it right away and I'm going to, I think I'm going to keep using it.
04:28 It's great.
04:29 Well, one thing that I got out of this, that's interesting.
04:31 Scroll down to where it has like the, how to get it.
04:33 You'll see like a whole bunch of links.
04:35 If you go down that page a little more, a little more, keep going.
04:38 Yeah, I think so.
04:40 There's a section.
04:41 Oh no.
04:42 Yeah, there you go.
04:43 There's a bunch of, it shows you all these different package managers that'll give it to you.
04:47 So if you want to get it from Rust, you can use Cargo or a macOS, there's Homebrew and Mac ports.
04:51 You want it on Windows, they interestingly recommend Scoop, which I've never used.
04:56 I've only used Proclity.
04:57 So I don't know.
04:59 I feel like there's like ice cream theme, just something for the Windows world.
05:02 But yeah, those are pretty interesting.
05:04 I was going to be snarky and say, do you require make to install just?
05:08 Yeah.
05:11 So I got no problem using brew install for my Mac, but I'm not going to install scoop for Windows.
05:18 I don't have any other need for it.
05:20 So there is pre-built binaries.
05:22 So I just use the pre-built binary for Windows.
05:25 It worked fine.
05:26 Yeah, this looks really great because my experience with make has been to just run the basic make command to build something.
05:33 And if it works, that's great.
05:35 And if it doesn't, I have no idea what to do because I feel like my knowledge of make is sort of like my knowledge of CSS where it's just been built up from little bits of knowledge over the years and I've never formally sat down and read through all the documentation.
05:49 - 100% JIT learning, like just enough time that you needed.
05:54 - Yeah, exactly.
05:56 - Yeah, like I actually have never really understood why phony targets were needed.
06:01 And this discussion in the readme of this, of Just actually talks about why phony is needed in the first place for make files.
06:10 and why you don't need them for just.
06:13 So it's kind of interesting.
06:14 - Yeah, very cool, very cool.
06:17 We'll move on to the next item.
06:18 Couple of comments for Al out there.
06:20 Teddy, hey, Teddy in the live stream says, "Love to automate the boring stuff.
06:24 "How I learned Python." Dean says, "Always recommend it to get started." Great fan, so yeah, that's pretty cool.
06:30 - Awesome, hey, thanks.
06:32 I always love hearing that.
06:33 - You bet.
06:35 All right, I love to hear from our fans of the show.
06:38 And so Roman Wright, who worked on Beanie, the, I believe, pedantic-based model query for ODM for MongoDB, recommended something else this time.
06:51 We already covered Beanie.
06:53 Something called strong typing.
06:55 So this is a decorator, this is from Felix Lassie.
06:59 It's a decorator which checks whether a function is called with the correct arguments.
07:03 So if somebody goes and puts type annotations on their code, That's cool, the editors like PyCharm will say, you're doing it wrong when you're doing it wrong, or they'll give you autocomplete and information on the arguments and so on.
07:17 But Python, that's like a hint, right?
07:21 Called type hints often.
07:22 Because it's a hint, it is not a requirement.
07:25 And so if you want to make sure that certain types match up basically, you can use this decorator.
07:32 And there's not a lot to this one, but go over to the read the docs.
07:36 There's a stay strong little character there.
07:39 But the idea is if you had this thing that was like a multiplier, took an A int and a B int, you could pass other stuff.
07:45 But if you pass, like if you could pass like three or four to multiply, but if you pass like, hello world, it's just going to try string times string, which there's probably a cool Watt outcome that we could get there, but that's not what happens in Python.
07:59 We get a type error, right?
08:00 If you do a string times a number, you get a pretty interesting outcome.
08:05 And this is something of a WAP.
08:06 If you do like hello times four, you get hello, hello, hello, hello four times, which has always been weird.
08:12 When I learned you can multiply strings, it kind of freaked me out, but I've come to find it useful.
08:16 So what do people do?
08:17 Well, they're like, well, this won't stand.
08:19 We need to check the type.
08:21 So we're gonna say, if is instance, the first parameter and an int, and is instance the second one, we can do it.
08:27 Otherwise we're gonna report an error.
08:29 Don't do that.
08:30 Instead, what you can do is you can use this match typing decorator.
08:35 you could just say @match typing, and it's going to take the arguments based on the type hints and validate them.
08:42 So if you pass in the right one, great, it'll give you an answer.
08:45 If you pass in something that does not match the type annotations described, it'll say, it'll raise a type mismatch exception.
08:53 And this can be nested down.
08:55 So for example, one of the examples is it takes a list and let's see, it takes a list, which is a union of strings, ints and tuples.
09:04 So if you give it a list that has either a string, int or a tuple mixed heterogeneously into the arguments, it'll take that just fine.
09:13 But if you give it some other type like a list that happens to contain one of the elements as a date time, it'll give you this exception.
09:19 So it's not just, "Oh, it took a list." It has the transitive property of analyzing the types is validated there.
09:27 So pretty interesting. What do you two think?
09:29 >> Yeah. So the difference between this and something like mypy is that this operates at runtime, right?
09:35 >> Right, exactly.
09:36 Because you could do all the mypy stuff you want, and if people don't run it, well, you're not going to get any information out of it, right?
09:42 >> Yeah, that was something that I was really surprised to learn when I first learned type hinting was that, really, Python's type hints don't really affect the runtime code at all.
09:52 It's just set up for static source code checkers like mypy.
09:56 So it doesn't turn Python magically into a statically typed language.
10:01 It's just for these static source tools.
10:04 >> Yeah, exactly. That's mypy is.
10:06 This is the other side of that.
10:09 This is the one-time one.
10:11 Maybe you would use this in the case where you're building a package or library and you've done everything correctly, but someone else is consuming it potentially incorrectly, and you can't control whether the world uses mypy or not.
10:23 You just wrote a library.
10:25 You could use this on say the boundary of your library, not everywhere, just on the boundary to make sure the stuff that goes in and out is valid.
10:33 >> This would be really helpful for stuff that I work on because usually I'm just writing code ad hoc that does this runtime checking.
10:41 But it's really nice that I could just throw in a function decorator and just add that capability, and that's all I have to do.
10:48 >> Yeah, absolutely.
10:49 >> Yeah, this is great.
10:51 >> So clearly this is adding code, your code.
10:55 So yeah, I'm curious about the performance.
10:59 - Yeah, so Teddy, he out there in live stream asked, do you know if there's any potential loss performance since it's running at runtime?
11:05 I'm gonna say, I am certain there is a loss performance.
11:09 Unfortunately in Python, calling a function is a relatively slow operation and doing a decorator is effectively calling a function.
11:18 So it's got to be slower.
11:19 That's why I would say put it just on the boundaries, you know, something like that.
11:24 But I mean, the alternative is if you actually wanna do these tests, if you actually wanna do that validation, it's an if statement and multiple is instance ofs all over the play, right?
11:34 So if you're gonna do that validation anyway, you're already calling, it's just not on the outside, it's on the inside, right?
11:39 So good question, I don't know.
11:42 - Yeah, another question from Ben Lindsey, do you know how this compares with Pydantic's validate arguments decorator?
11:49 - I don't know, but I'm a big fan of Pydantic and the validate arguments decorator is exactly the same type of thing that we're talking about.
11:56 So for example, like you just put the @validate arguments.
11:59 The thing is that I did notice somewhere that yeah, here it is.
12:03 Like this validate arguments decorator is in beta for whatever that means.
12:08 It won't be concrete until V2, identic.
12:12 But that may well be more concrete and more formalized than this one, right?
12:18 Although this is more standalone, right?
12:20 So you don't necessarily, It feels like a little tiny thing that you just plug in on there.
12:24 Pydantic is doing a lot.
12:26 I'm a fan of Pydantic.
12:27 So yeah, good question, Ben.
12:29 All right, Al, you got the next one, right?
12:31 >> Yeah. So I have a new book out.
12:34 It just came out at the end of June.
12:36 It's called The Big Book of Small Python Projects.
12:39 So a lot of my books have been for people who are total beginners or relatively new to not just Python but to programming in general.
12:48 >> Generally people who have boring stuff?
12:50 Yes, oh man, so much boring stuff.
12:54 Actually, you have books on games and things as well.
12:58 Yeah, yeah, that's the two approaches I have to tricking people into learning how to program is getting away from Excel and then also learning how to make video games.
13:07 Seems to be really common pathways into programming.
13:11 So I've also noticed that with a lot of beginner tutorials, people learn the syntax and they learn all the concepts like loops and variables and things like that. But when it comes to actually working on their own projects, they're sort of stuck and they're just left staring at a blank editor and not really knowing how to proceed from there. And a lot of people will give them, usually the two bits of advice that people get are, oh, you should work on open source projects, or just read the code for open source projects, which is actually pretty terrible advice for for beginners because a lot of open source projects might not be well documented.
13:47 They're written for professional software engineers.
13:51 There's a lot of concepts.
13:52 - Yeah, there's a huge difference between something that is absolutely polished and meant to be used in many situations in the real world.
13:59 Like you might learn a lot by working, looking at Django, but most of the time you'll probably just be confused.
14:04 You're like, why is this so complicated?
14:05 Oh, it's so complicated because, you know, a million websites use it in weird ways and that's why it's complicated.
14:11 That's not a good learning tool per se.
14:13 - Yeah, especially for someone who just learned about, you know, how to call functions and how to create classes and pretty basic things like that.
14:20 So I spent, I think, I think I was working on this on and off again for about two or three years, but I wanted to create a collection of small little programs, mostly like games or puzzles or little simulations or things like that, where they were all just really simple and easy for beginners to read through, and then they can understand, oh, this is how all of these concepts I learned get applied to an actual program that does something. So these aren't code snippets. They're not just like tiny little functions or things like this. This is programs that you can actually copy the code yourself and then figure out how they work. So I have about 81 of these projects all together. They're all under I set a limit of of 256 lines of code just as an arbitrary power of eight to set it to. And they are all text based games. So they're fairly old school looking, like a lot of the games that people were programming in basic in the 1980s and 90s. But the plus side of that is that all of the games are really simple and you don't have to install additional libraries or modules or things like that. You can pretty much just type the code in and it just uses the Python standard library for all of this.
15:38 I have a few of these programs that use a few other modules as well, but for the most part you can get pretty far with just text and just ASCII art.
15:47 And also, even if you already know Python, these programs are great just for ideas of if you want to learn another programming language and just get used to how things work in that.
15:56 could find the idea for a blackjack game from this collection of programs, or this birthday paradox calculator, and all sorts of these little projects right here. And of course, this book is also freely available online at inventwithpython.com/bigbookpython. I'm starting to get reviews coming in on Amazon, and they seem to be pretty positive. So I'm I'm really hopeful about people just being able to take the next step in learning to code with this book.
16:27 - Yeah, cool.
16:28 - Cool.
16:29 - Yeah, and then the other book that I had that came out in November is "Beyond the Basic Stuff with Python," which is sort of the follow-up book to "Automate the Boring Stuff with Python." I had a lot of people who were asking me, "Oh, I really like to automate.
16:44 What should I read next?" And I had some things that I would tell them, like Fluent Python is a really great book, but it's also like 800 pages or 800 pounds or something.
16:56 It's a really huge book and the information in it is great, but it's really intimidating to take this book and it's like, okay, read this one next.
17:06 So I wanted to cover a book that had sort of the best practices for a lot of like software engineers.
17:14 So there's sections on like how to name your variables or how to do code formatting.
17:19 I talk about the black code formatting tool. I talk about type hints and how to write documentation.
17:25 I have a very superficial coverage of Git and GitHub and how to use version control. And just you know, and I even dive into like, what exactly does Pythonic mean?
17:38 Spoiler alert, Pythonic basically means anything the person you're talking to wants it to mean at at the time. But yeah, just sort of a lot of the things that you don't really get in your typical Hello World tutorial. These are the sort of tidbits that you would pick up with experience over over years of experience, I guess. But I just wanted to collect all of that advice and information and best practices into a single book. So yeah, that's also available online at the invent with Python.com website. Cool.
18:10 Couple comments from the live stream. John, the hand says beyond the basic stuff was great for learning to do things Python way.
18:16 And wow, great to see you Mr. Swigert.
18:19 Seems like only yesterday I was promoting your last book at Bay Piggies from--
18:23 - Oh, hey Neil, how's it going?
18:25 - Cool.
18:26 - Yeah, very cool.
18:27 Congrats on the books.
18:29 Brian, let's talk about something completely different than books.
18:33 - Like notebooks, yes.
18:37 Let's talk about notebooks.
18:38 Thanks for popping that up.
18:40 Yeah, so this was another suggestion.
18:43 this suggestion came from David Nicholson.
18:45 Thanks, David. I thought we'd covered this already, but then I looked in, but we haven't, and I looked into it, and I obviously haven't played with it yet.
18:55 But okay, so Testbook is very cool.
18:58 Testbook, the idea is to test your Jupyter Notebooks.
19:02 I think we've covered a couple of ways to do that, but this is a neat perspective.
19:07 The perspective of this is you've got a notebook with maybe, let's say functions in it, and you want to check those.
19:16 You want to make sure that you want to write tests against those functions.
19:19 Instead of putting the tests in your notebook, put them in just a test file and run it with pytest or unit test or something.
19:29 To do that though, let's say I want to run a function foo, and I want to do it from another file, I've got to get that definition of foo into my test code.
19:41 So what TestBook does is it has a decorator that you can either put it on your test or a fixture that goes ahead and runs the, one of the things you can do is run your notebook before the test runs.
19:55 Oh yeah, this is really cool.
19:57 So you have a decorator which has a path to the IPYNB file and execute equals true.
20:03 And by the time it gets to your code, it's already going to run that.
20:06 things defined like a function or variables defined within the notebook will just be accessible through the input parameter there.
20:13 Yep, and the test gets a fix, you can have a fixture to be able to grab values, references.
20:20 So the example we're showing right now shows pulling a function in, but I imagine you can pull in really anything, any name that exists within the notebook to be able to test it.
20:33 Some of the neat things that it includes right off the bat is, it's nice that it isn't just pytest.
20:39 You can use it with unit test.
20:40 Apparently also with Nose, but don't do that.
20:43 One of the things you can do also is, in the original example of decorating a test, it's going to run that notebook for every test it's decorated.
20:54 You might not want that.
20:55 You might, but if you want to run it all just once, you can put it in a fixture and then return the fixture.
21:02 That's a cool thing.
21:03 One reason why you might want to run it multiple times is if there are interactions between the different parts, and you want to completely isolate those tests.
21:12 Another thing that's built into it is patching.
21:15 You don't have to import mock, you can patch different parts of your Python notebook code like mock.
21:25 You can patch it right through this. That's pretty neat.
21:28 >> Yeah, that's pretty neat. I like it.
21:30 Al, what do you think?
21:31 - Nice, yeah.
21:32 I haven't had a lot of experience with Jupyter Notebooks, but it's sort of becoming the main way that a lot of people are being introduced to Python, especially if they're coming from the sciences or academia.
21:42 - Yep. - Yeah.
21:43 And so getting sort of a lot of informally trained software engineers up to speed with unit testing and other practices like that, it's definitely something I can get behind.
21:53 - Yeah, that's cool.
21:54 And getting the ability to call those pieces or interact with those pieces outside the notebook is quite tricky so this is a neat way to do it.
22:02 I mean, we've got paper mail, but I'm not sure exactly how that folds into testing and stuff like that, right?
22:07 - Right, actually-- - Yeah.
22:09 - Yeah, I don't think so.
22:09 - I think it's more like inputs and outputs as a whole notebook, not like, let me get a hold of the function in the cell seven and try to call that.
22:18 - Yeah, also the target audience is different.
22:21 So the target audience for your notebook itself is different than you trying to test your code.
22:27 So keeping the test code out of the notebook, I think is a nice thing to keep it clean.
22:34 - Yeah, I totally agree.
22:36 Taking a step back real quick, Neil also asks, are the small programs in your book, Al, compatible with MicroPython or CircuitPython?
22:44 - Probably not.
22:46 I don't know, I haven't taken too much of a look at MicroPython, but I do try to keep all the source code as simple as possible and not really rely on like the file system or making network connections.
23:01 Mostly it's just standard IO input output streams for text.
23:06 So, you know, if it can run print and input then likely it can run these programs.
23:12 - Yeah, maybe you just have to make the little lights blink and some sort of Morse code.
23:16 - Yeah, perfect.
23:18 - Nice.
23:19 All right.
23:20 Something that is a little bit mysterious to a lot of folks I think, partly because it's somewhat discouraged, but not always, is from package import star, right?
23:30 While sometimes discouraged, 'cause you probably shouldn't, there probably are situations where you wanna do that.
23:36 Like if I've got three sub-modules and I wanna take the elements in them and then drop them into the top-level dunder init for a package so that I can just say package name.items, but not organize them into one giant file, for example.
23:49 That might be reasonable.
23:50 The way that you control that is you work on the dunder all definition at the top of your package, right?
23:58 And in there you can say, oh, here are the names of the things that I would like to export.
24:02 If you import star rather than everything, give them these, right?
24:07 Maybe you define some weird thing called Django and it's not meant to override Django or something like that, right?
24:13 You wanna leave that out.
24:15 So how do you manage that?
24:17 Well, there's this project over on GitHub called AutoAll, auto-all, and the idea is it somewhat automagically manages the dunderall variable for Python modules.
24:30 So there's a couple of ways in which you can do it.
24:32 You can exclude certain things, you can clearly differentiate what's meant to be treated as an external item and what's meant to be treated as an internal item.
24:43 You don't have to worry about continuing to update the dunder all and so on.
24:48 So you just pip install it.
24:50 And then the most, it seems like the recommended way I guess, is you would fall somewhere in your script at the top level, like at the function or class level, right?
25:00 No tab space, no spaces, no indentation.
25:03 You say start all, then you write a bunch of code functions and so on.
25:07 And then you say--
25:08 - You mean auto all dot start all?
25:10 - Yeah, yeah.
25:11 If you, yeah, if you, exactly.
25:13 If you import it from there, right?
25:14 I guess you could even import star from there, but you say start all, and then you write a bunch of code, and you say end all, and then basically between those two markers, those are the things that go into your done all variable.
25:26 There's something about classes, it will not work for classes or variables as, sorry, take it back.
25:32 It will with the start all, end all, but there's also another way that only works on function, and that is to put a decorator onto the function, which I think, I like this a lot, but the fact that it doesn't work with classes, It sounds like that should actually be a PR folks.
25:46 - Yeah.
25:47 - A little thing that, an extra one like public class or I don't know, whatever.
25:51 But that seems pretty cool.
25:52 So you just say @public on a function and then that will add it to the dunderall.
25:57 So if you wanna export three functions from your module, you just put @public on those.
26:00 And that way when you're looking at it, it's like really clear.
26:02 These are the public functions and the rest aren't.
26:04 I mean, you could still from module import name, but not through the all, right?
26:10 - Yeah.
26:11 - Okay, anyway, it looks pretty cool, right?
26:13 - Yeah, that is actually a really nice way to just have this automatically taken care of.
26:18 I mean, ideally you're not really doing the from module import star all too often, or rather, ideally, I'm the only person in the entire world that should be allowed to do that, and everybody else will have to do it the proper way.
26:32 - It's a bad idea, don't do it.
26:33 But it's very handy, no.
26:35 - Yeah, this is really handy.
26:36 - Yeah, Dean out there in the live stream says, this should work with a context manager.
26:40 Yeah, it probably should.
26:41 I think the challenge would be then you'd have like all of your implementation indented, but still pretty cool.
26:46 Yeah.
26:47 So actually I'm reminded of one of the places I do do, I do do import all or import star is, is in, Dunder and it files for packages.
26:57 Yes, exactly.
26:58 In those cases, I often do only in, I've got a couple of modules that have my interface and I pull everything in from there.
27:05 so, those are, those are cases where that isn't, that is something that happens and then you're faced with, "Well, what if I want to put another function that isn't part of my public interface?" Then you have to jump through hoops.
27:17 I'd probably use it in those cases.
27:20 >> Yeah. I don't think it's broadly applicable, but for the people who are really trying to carefully manage their Thunderall, seems nice, straightforward, simple.
27:28 >> Yeah.
27:29 >> Yeah. All right. Al, I think you got the last one, right?
27:33 >> Yeah. I am working on another book.
27:37 I have a really bad book writing problem.
27:39 I keep thinking that this will be the last one and then I have ideas for 10 or 20 more.
27:46 But the book that I'm currently working on and I'm down to the drafts of the last two chapters is a book on recursion. So this is currently my untitled recursion book. But yeah, I gave a talk at North Bay Python, I believe in 2018 or 2019. That was an introduction to recursion. And recursion is one of those things where a lot of people find it very intimidating, or even just outright magical. And it's, it's this thing that seems to be like only for advanced programmers or something like that. But I started taking a look at it.
28:21 Programmers who make a mistake.
28:22 Right, exactly.
28:23 Accidentally.
28:24 Yeah, just just for some general background. recursion is when you have a function that calls itself. And this is, it sounds like it won't work. And oftentimes it won't, you'll, get a sort of an infinite loop of recursive function calls and then it crashes your program.
28:41 But there are recursive algorithms where this is a really handy technique and allows you to do really sophisticated things in in not that much code. However, a lot of people find it really confusing. But more than anything, I found that it's just poorly taught. Most people will probably learn this from a computer science professor, or they'll be studying it as a way to prepare for job interviews for the coding section. You know, there's a lot of times where people will be writing out an algorithm on a whiteboard and their interviewer will say like, okay, and now can you do the recursive version of this algorithm as a quick gotcha. But yeah, there's the short of it is I realized that a lot of times people don't really teach the concept of the call stack. And without explicitly knowing about what a call stack is and how it works. A lot of what recursion does kind of it just seems magical because you're missing this huge piece.
29:35 I found out so many other things about this.
29:38 I thought, "Hey, I could write a quick little tutorial on recursive functions and make a talk," and then that just ballooned into a giant book now.
29:48 >> That's how I end up with courses.
29:50 I'm like, "Oh, that'd be neat little thing to play around with.
29:52 Why have I spent the last month doing this?" >> Yes. I'm hoping to have this book probably done either at the end of this year or early next year in 2022. But yeah, so a book that just covers recursive algorithms, and and why people find recursion to be so intimidating and how it really isn't. And even how oftentimes, it's actually not the best technique to use. You just want to write straightforward, simple code. But if you really want to show off how smart you are, and annoy your coworkers that way.
30:27 Recursions also really create for that.
30:29 >> What I like about it is if you have hierarchical data, it matches that really cleanly.
30:34 >> Yes.
30:35 >> You want to traverse a tree, but in a real simple way, you want to work with an algorithm that is iterative in the sense, the previous step naturally, the answer that leads to the next one, those types of things.
30:46 It's a super elegant answer.
30:48 >> Yeah. I found that recursive algorithms are really great when your problem has a tree-like structure and also involves backtracking.
30:58 Otherwise, there's probably, you probably just need a loop or some iterative way of solving it.
31:05 You can also come up with a cool joke like the one we had on episode 236.
31:09 There are so many recursive jokes.
31:12 I actually opened up my talk at North Bay Python with just like, okay, we just got to get that out of our systems, do the whole, you know, in order to learn about recursion, we first have to learn about recursion, these jokes that we've heard like millions of times.
31:27 - Yeah, people can check out the little cartoon graphic thing on episode 236.
31:32 - Yeah, I was gonna ask you if you're--
31:33 - Brian, you got anything you wanna just throw out there at the end?
31:36 - No, I've just been working a lot.
31:39 I was just, one question, I was just gonna think that maybe Al's book was about how to write a book about recursion.
31:45 (laughing)
31:46 - The Making of is something that I've also been thinking of after I've published it.
31:50 I feel like a book on meta classes and meta programming might be very relevant.
31:54 And that's all right.
31:56 I got a couple of things to cover from my extras.
31:58 Okay.
31:59 First I had talked about, Oh my posh.
32:02 Oh my posh, which I think is a really cool, like, Oh my Z shell type of thing, but for.
32:08 PowerShell.
32:10 And if you use the new windows terminal and you get the new PowerShell seven and set that to be the default, then you get these really beautiful, nice prompts and auto-complete and all those kinds of things.
32:20 So those are really neat.
32:21 People can check that out for all the posh shell stuff.
32:25 But someone was asking for something that would do a thing that is really cool.
32:30 Like what if when I, and by the way, because we gave it a shout out, I was dreaming of something that would automatically activate virtual environments when I CD'd into a structure that contained in the tree somewhere a virtual environment, which is cool.
32:48 So they dug around and said, I found this thing called posh-direnv, which does that.
32:54 So as you change into the directory, it will automatically activate virtual environments.
33:01 >> Nice.
33:02 >> Nice.
33:03 >> Yeah. So that's pretty neat.
33:05 So people can check that out as a follow-up.
33:07 Another thing, one of our listeners, Einstein Vincent, I believe, was the one who sent it over. Thank you for that.
33:14 Just said, "Hey, quick shout out.
33:15 Your show has been super helpful to us.
33:17 that's been inspiring a bunch of us scientists.
33:20 We're here in Iceland, and I believe also at Harvard, if I recall correctly.
33:24 And they now published an article using Python, a scalable method of determining physiological endotypes for basically a sleep apnea study of trying to turn this into more of a continuum rather than yes or no, you have, yes or no, you yes, do, or don't have sleep apnea.
33:41 So really cool just to see listeners listening to the show, using some of the packages and doing cool stuff that help people.
33:47 - Yeah, that's good.
33:48 - One more follow-up, two, three more follow-ups actually, but next one, really quickly, I've been having such a challenge with email for two years and I have finally, I think, solved it, the beast, I believe.
34:02 I have had hundreds of emails from years ago that needed action and finally I've gotten back to almost everybody down to just a handful of emails and I'll have them all done.
34:12 But anyway, I wanna recommend two email clients, one for the Mac is Newton, pretty cool, And then I'm gonna give superhuman a try, but it takes a while to get set up on that.
34:21 If you're out there struggling with email, check those out.
34:23 And so we've heard about cloud computing.
34:26 That's where you might run your program in the cloud.
34:28 You've heard about virtual environment, or sorry, virtual machines.
34:31 That's where you might fire up a computer that runs in a container or a virtual hypervisor.
34:36 And then you can interact with that in like its own little way.
34:39 But Microsoft, apparently, I was just reading like 15 minutes before we started.
34:42 I thought I'd throw this in there.
34:43 They just revealed not just Windows 11, but Windows 365, which is basically you buy Windows and the thing hosted in the cloud, so you just like, I don't know, web browser to it or something, and then you have a computer with all your files that's instantly on.
34:57 So, I don't know, I thought that was kind of interesting, throw that out there.
35:00 - Yeah, it's like Office 365 except the entire operating system.
35:03 - The entire computer with all your files saved there, yeah, exactly.
35:07 Probably expensive, I have no idea.
35:09 Last thing, we talked about Flock No, right?
35:13 We talked about Flock and the vanishing third-party cookies and the stuff that Google is trying to do.
35:18 And then remember that brand new point that they received significant feedback that was not totally positive for them.
35:23 Yeah.
35:24 So, you know, parallel to that, I think is really interesting is that Apple also had their do not track thing that they put on their phone, which.
35:32 Is fine, but I think it, it just needs to be way more than that, but yeah.
35:35 So they have that.
35:36 And would you be surprised that only 25% of the people said, yes, please track me.
35:40 I'm actually surprised that 25% of the people said yes.
35:44 Like, if it's over 5%, it's blowing my mind, right?
35:47 Like, yeah, please.
35:48 - Who's saying yes?
35:49 It's, uh.
35:51 - Exactly.
35:51 So here's an article.
35:52 Facebook and its advertisers are panicking as the majority of iPhone users opt out of tracking.
35:58 And I saw that 20% of ad spend is now moved away from iPhone and towards Android because Android doesn't, you know, they're happy to track you.
36:06 That's Google.
36:06 - Yeah.
36:07 - But also, just, I think it's very meta and funny.
36:09 So I have my VPN that has a ad blocker plus cyber, like basically virus malware detector at the network layer.
36:17 Notice there's a big gap in me showing you this article up here.
36:20 That's, I was trying to show me the ad about the advertisers and my network, my VPN is blocking it, which I just love it.
36:27 So anyway, those are all the things that I had to share there.
36:31 Al, you got anything else you wanna throw out there for everyone?
36:33 - Yeah, outside of the books, I'm also working on my open source project called PyAutoGUI.
36:39 This is a GUI automation module for Python where it's a module that lets your Python scripts control the mouse and keyboard.
36:46 So if you have some software that you want to automatically click and type things into, you can write a script using PyAutoGUI to do that.
36:53 It works on Python 2 and 3, and also on Windows, macOS, and Linux.
36:59 I feel like I've been neglecting this project for the longest time, but more and more people are using it.
37:04 So I really want to start adding more and more features to bring it up to speed with a lot of other GUI automation libraries that are out there.
37:12 So if anybody is interested in contributing, I have the GitHub link and you can also just Google for PyAutoGUI to find more information about that.
37:22 - That's cool, I found out by DuckDuck, Googling with DuckDuckGo.
37:25 - Yes.
37:27 - I still have a problem saying Google as the verb.
37:31 - No, I do too, all the time.
37:32 - I finally got over using guys as a general neutral pronoun but now I still have problems saying Google all the time.
37:38 >> Yeah, it's all hard.
37:40 By the way, notice over here.
37:42 >> I still have trouble not telling people the MapQuest something.
37:45 >> Yeah, I know. It's good except those little arrows to move each around on the map, the little bars on each side are so clunky.
37:54 You got to print the thing out for like five pages and follow the pictures.
37:57 Now, but so one thing I do want to give a quick shout out to the guys that read the docs, Eric and crew over there.
38:02 They have an ad right here and it says, "Sponsored ads serve ethically." You know what that's based on not tracking and retargeting.
38:10 That's just, hey, there's something to do with this Python project.
38:13 So this ad has to do with the context of what is here.
38:17 It's just it's relevant to the content I'm already looking at.
38:19 Good old fashioned.
38:21 Astounding.
38:22 Just like magazines and newspapers and stuff like that.
38:25 And it's not about finding hot singles in my local area.
38:28 That's great.
38:30 Exactly.
38:32 All right.
38:33 Cool.
38:33 Yeah. Cool. Thanks.
38:35 Thanks, Al, for joining us today. And Brian, as always, thanks for having me.
38:39 Yeah, you bet. Thanks, everyone, for listening.
38:41 Thanks for listening to Python Bytes. Follow the show on Twitter via @pythonbytes.
38:46 That's Python Bytes as in B-Y-T-E-S. Get the full show notes over at pythonbytes.fm.
38:52 If you have a news item we should cover, just visit pythonbytes.fm and click submit in the navbar.
38:57 We're always on the lookout for sharing something cool. If you want to join us for the live recording, just visit the website and click "Livestream" to get notified of when our next episode goes live.
39:06 That's usually happening at noon Pacific on Wednesdays over at YouTube.
39:11 On behalf of myself and Brian Okken, this is Michael Kennedy. Thank you for listening and sharing this podcast with your friends and colleagues.