Learn Python with Talk Python's 270 hours of courses

#244: Top 10 Real Python Articles of 2019 Transcript

Recorded on Friday, Nov 8, 2019.

00:00 We've come to the end of 2019. Python 2 has just a handful of days before it goes unsupported,

00:05 and I've met up with Dan Bader from realpython.com to look back at the year of Python articles on his

00:11 website. We dive into the details behind 10 of his most important articles from the past year.

00:16 This is Talk Python to Me, episode 244, recorded November 8th, 2019.

00:22 Welcome to Talk Python to Me, a weekly podcast on Python, the language, the libraries, the

00:40 ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter where

00:45 I'm at mkennedy. Keep up with the show and listen to past episodes at talkpython.fm,

00:49 and follow the show on Twitter via at talkpython. This episode is sponsored by

00:54 linodeandbrilliant.org. Please check out what they're offering during their segments. It really

00:58 helps support the show. Hey there. I want to take just a moment before we get to the interview

01:03 and say thank you. It's the end of 2019. Looking back, it's been a great year for the podcast and

01:10 all the other stuff we're doing, like our courses, and it's been really humbling to get messages from

01:15 all of you about how the podcast is helping you in some way or the benefits you're getting from it.

01:21 And I just want to say thank you for listening because it's a true honor to be able to create

01:25 this podcast for you. It's a lot of work, but it's entirely worth it. It's really, really great,

01:31 and it couldn't be done without you listening and sharing it. So thank you, thank you, thank you.

01:36 Hope your 2019 was great as well. Now let's chat with Dan.

01:41 Dan, welcome back to Talk Python to Me.

01:43 Hey, it's great to be back, man.

01:44 It's great to have you back. It's been a while since you've been on Talk Python, but

01:47 not too long ago since you were on Python Bytes. That was fun.

01:50 Yeah, that's right. We practically just finished recording that. And yeah, it was great with

01:55 Cecil Phillips and yeah, I had some good links that week, I think.

01:58 Yeah, absolutely. So I'm pretty excited about 2019. It was a good year. How was it for you?

02:03 It was a very, very busy year, I would say.

02:07 Yeah, I feel like for you guys, like RealPython has come along a long ways. You've got a lot of

02:13 authors, you've kind of got this process going, you've got your editorial, your editing, and

02:17 overseeing how the content creation is going. And you're making a big difference, I think.

02:22 Thanks. That's good to hear. And yeah, it's just been this incredible year. We're at 75 authors and

02:29 video instructors published on the site now. So I want to get to 100 next year. That would be a nice,

02:34 cool achievement, I think. And we also just recently hit 2 million visitors, like unique visitors or

02:41 readers in a single month, which is kind of this incredible... Let me... I can almost... It totally

02:47 sounds like I'm super bragging here, but I literally can't wrap my brain around that. It's just kind of

02:53 nuts and really cool just to see that growth and how it's resonating and how we're getting really,

02:59 really positive feedback. Yeah.

03:00 Yeah. I think that's really positive and congratulations.

03:02 Thank you.

03:03 Yeah. And I think it speaks one to all the work that you're doing that you talked about. It also speaks

03:08 to just Python's growth in general, right? Like you're riding two curves and they're both going

03:14 in the right direction.

03:15 Yeah, that's true. So how was your 2019?

03:17 My 2019 was amazing. Didn't skip a single episode on any of the podcasts. And I think that's a pretty big

03:24 accomplishment actually.

03:25 That's huge. Yeah.

03:26 Yeah. And released a bunch of classes. I feel like we've covered some important stories

03:31 on the podcast, right? That's one of the things I try to do. We can cover every web framework

03:36 and the person who creates it and that's great and so on. But I really want to highlight that

03:40 Python is not just for web developers or like straight down the middle of the road data scientists.

03:46 Yeah.

03:46 We've had medieval Islamic philosophers and we've had people doing machine learning for particle

03:54 collisions and all sorts of stuff that might have been back in 2018. But those kinds of stories are really

04:00 interesting. I think we had a decent amount of those and I'm really happy to be able to share

04:05 those edge stories that I think are so interesting.

04:07 Yeah. Yeah. I think that's super cool. And then I think a podcast is just such a great format for it as well,

04:12 where somebody can come on the show and join you there and really give the listener a chance to

04:18 understand why this is cool and what the motivation. That's always the most interesting thing for me

04:23 when I listen to your show, figuring out like, okay, why is your guest doing that? Why are they so into

04:27 researching Islamic philosophy with Python, which are two topics that I would have never imagined

04:33 you would combine in some way. And then I listened to the show and I'm like, oh man, it's so cool how

04:37 broad this is, what people are doing with Python.

04:39 Yeah. You listen to the story and it makes perfect sense. You're like, of course you should be doing

04:43 that. And the thing I like about those types of stories is there's a lot of people that think,

04:48 oh, I'm not a programmer or it doesn't make sense for me to do that or whatever. Like,

04:52 I'm just a stock trader. I'm just a biologist. And then you hear that and you're like, all right,

04:57 if somebody can use it for philosophy, thousand year old scrolls, I should be able to find a way to

05:02 make use of this in my much more mainstream type of job. Right. It's like, yeah, obviously there's all

05:08 these amazing things people can do. They just got to be a little creative to do it.

05:10 Yeah. Yeah, absolutely. I feel like we talked about this before, but this whole idea of the dark

05:14 matter developer, someone who doesn't actually really identify as a developer or programmer,

05:19 but there's so many people out there who are practically programmers or they're working with

05:25 code, they're writing code, but they don't really see it that way.

05:29 A big enough part of the community to actually come along and come to the conferences or blog about

05:34 programming. They're probably blogging about something else that they care about. Something

05:37 like that, right?

05:38 Yeah. Yeah.

05:38 Yeah. Sweet.

05:39 Cool. Well, let's talk about what we're going to focus on for this show. So the idea is we're going

05:43 to take 10 of your popular bookicles, book articles, your articles-

05:49 That should be a new one.

05:50 Yeah.

05:50 So we're going to take our near book style on real Python and just pick 10 of them. We're going to

05:56 call it the top 10, but it's not necessarily top 10 by your traffic. It's kind of the ones you wanted

06:02 to highlight from the year, right?

06:03 Yeah. So yeah, I really wanted to give a chance to sample a wider variety of topics because if you go

06:11 purely by traffic numbers, things are just going to get overshadowed by popular terms that people

06:16 search for on Google.

06:16 Look, it's for Django articles or whatever, right? And just because people are searching for that or

06:19 whatever.

06:20 Yeah. And so, yeah. So we kind of assembled a list of 10 articles that we wanted to highlight and then

06:26 go over and then share with you.

06:27 All right. Where are we starting?

06:28 Sweet. So we're starting with an article that's called How to Run Your Python Scripts by

06:34 Leo Danis Pozo Ramos. And it kind of sounds simple, right? You just go-

06:41 Right. Don't you just say python space script.py?

06:45 Yeah. I mean, that's what we do most of the time, right?

06:47 Some of the time, yeah.

06:48 Hit control R or something like that. F5. And this article is cool because it, of course,

06:56 talks about that. But then it goes really, really deep into the behind the scenes and

07:02 what some of the other ways are that you can possibly use to run Python code. So you could

07:07 just load the string from Office Script and then just eval it. Or there's the import lib module

07:14 in Python 3 that you could use. And there's all kinds of other more complex methods where you get

07:21 deeper and deeper into CPython.

07:22 You could do python space dash C and like some code, right?

07:27 You could also do that if you wanted to run a code snippet from the command line. And I just love this

07:32 article because it starts with the really simple and straightforward and like main use case. And then

07:36 it goes deeper and deeper and deeper into all the different alternatives. And you know, what the

07:41 difference is between running a module with Python dash M versus actually just running it by Python

07:48 space from the command, Python space and then the file of the file name and running it from the

07:53 command line. And yeah, for that reason, you know, I wanted to highlight that article.

07:57 Okay. Yeah, that's really cool. And one of the things I like about a couple of the articles that

08:01 we're covering are I look at the title and I go, yeah, I know that. And then I look at the article

08:07 and it's like, I don't know how many words, but it's like, you know, readability suggests this might

08:11 be an over an hour to read this article. I'm like, wait, I thought I just, that was simple and I knew it.

08:15 And you know, when you, whenever I, that kind of makes me think, I'm like, oh, I actually might learn

08:20 something here. If I just pay attention, like this is going deeper or into a different area than,

08:25 because if I thought it was that simple and it's this, then it's clearly I'm missing something.

08:28 Yeah. As the kind of the person running the site and working on the platform there, like I love

08:33 seeing surprises like that because it's always a team of us that's working on the article. So we

08:37 have like multiple review stages and we review the outline and then we review the script and there's

08:43 like a technical review and just seeing these things kind of grow and you'll become a real Python

08:49 article is, I just really enjoy that process and being a part of it. So yeah, this is like a great

08:54 example, I think, of that. Yeah. Yeah. Quite cool. So covers a bunch of stuff and probably something,

08:59 you know, there's definitely a few suggestions in there that I didn't know. All right. What's number

09:04 two? And number two is called 13 Project Ideas for Intermediate Python Developers by Habib

09:11 Shopeyou. And this was born out of a lot of questions that we received over email or Twitter and

09:19 also most recently in our real Python community Slack where people were asking, like, I feel like

09:25 I kind of know how to use Python, but I don't know what I should build. I've learned the language. I know

09:30 loops. I know how to do strings. I create a dictionary, get stuff in and out of it. But what can I actually

09:35 build that like is the next step? Exactly.

09:37 Yeah. Because that's often very challenging. It's not just challenging on like maybe a lack

09:42 of creativity. It's challenging in like, oh, you want to be cool to build Instagram? Like, no,

09:47 it wouldn't be cool to build. It'd be very hard to build. It's like millions of lines of code.

09:50 You know what would be cool to build? As a timer, like, no, it's boring and it's too short. Like,

09:53 what is the right size where it's challenging, but I can reasonably expect to do it if I put in some

09:59 effort? Yeah. And that's a really hard one, right? Like I was back in the day when I learned how to

10:03 code or first started. I mean, I guess you never really stopped learning how to program.

10:07 I was in these like game development forums and there was every single week there was like

10:12 a new person joining and they were like, I want to build this MMORPG or like, I want to build this

10:17 like massive thing. And so everybody was working on these like massive projects that never really

10:21 went anywhere. And I think that could be really, really frustrating. And so my answer to that question,

10:25 you know, what should I build as an intermediate developer was usually like, just pick whatever,

10:29 you know, just take a command line app that you use and try to emulate, like try to write your own

10:34 version of it. But the problem is that doesn't really work for some learners, for some students.

10:39 And so we wanted to give them a list with ideas, you know, here's some things that we think you could

10:42 probably pull off. You have a fighting chance of actually like building this app, right? And it's

10:47 not going to be a world of Warcraft, but it's going to be a cool like alarm tool or a little file

10:52 manager or a little note-taking application. Yeah. Give us a sense of some of the ideas you got there.

10:58 Yeah. So the ones that I just mentioned.

10:59 Yeah, exactly. So MP3 player, URL shortener, file rename. Yeah. That's really nice.

11:08 Contact book, I think is also something interesting where, you know, there's different ways you could

11:12 store the data could just be like a little, yeah, like an address book where maybe you ask, you know,

11:18 it could be as simple as just storing a dictionary to a text file, or then you could get progressively

11:23 more interesting there and have a little database maybe.

11:26 You could use SQLite and then you could start using SQLAlchemy because, you know, you don't

11:30 want to be writing inline SQL and then, you know, become little Bobby tables.

11:35 Yeah, that's right. Well, you know, someone could take you a great free MongoDB course.

11:39 Yeah, exactly. Yeah. They could do a MongoDB back one.

11:42 All kinds of options there.

11:43 Yeah. They could totally like level these up. They could put them online, all kinds of cool

11:46 stuff. Yeah. So I like it. And you got it broken down to web, GUI and command line. That's pretty

11:50 good break.

11:50 Yeah, that's right. Yeah. We try to give like a high level overview and then depending on what

11:54 you're interested in, you could pick the right project for you.

11:57 Yeah. Super. All right. What's next?

11:59 All right. So I think we are at article number three. And what I wanted to highlight there is

12:05 the article is called Three Ways of Storing and Accessing Lots of Images in Python by Rebecca Stone.

12:11 And I think this article is cool because, again, it's something that I never really thought about

12:16 before. You know, I was like, OK, you know, my Django app uses a bunch of static images.

12:21 There's just a folder in there.

12:22 Right, right. That's slash static slash IMG or something, right?

12:25 Yeah. But what if that maybe doesn't work so great anymore? I think you're storing a

12:31 massive amount of images. You know, you have some, I don't know, some robot, some probe that's going

12:36 to Mars and you have lots, you have like terabytes of images. And where are you going to store them?

12:40 How are you going to make this manageable?

12:42 Right. Are you going to create some kind of like automated IoT doorbell that always snapshots,

12:48 whatever's close, right?

12:49 Yeah. And if your house gets broken in a lot, eventually you have too many images and you got

12:54 to figure out what to do with them.

12:55 That's right. Why are all these people at my house? You're killing my storage.

12:58 All right. So what are some of the suggestions?

12:59 Yeah. So it goes, the article goes into three techniques there. So the first one is, you know,

13:05 just like store them on disk as .png files or, you know, JPEG or what have you. And then the

13:10 second option is using a memory mapped database called LMDB. And the third option is using a

13:16 hierarchical hierarchical data format like HDF5. And the latter two, I'd never really heard about before.

13:27 But it turns out, of course, that there is a lot of Python tooling available for these things.

13:34 And so they provide a number of interesting features. So for example, there's a compression

13:39 that you could use. So to potentially limit your disk usage. And there's just lots of good tooling,

13:46 if that's a problem that you're facing, that people can use with Python.

13:50 Yeah, this is interesting. Like I'd never heard of LMDB, but apparently it's lightning memory mapped

13:55 databases, which sounds fascinating.

13:57 It sounds, yeah. It's like, I should definitely check that out. Find a use case for that. Cause that

14:01 sounds cool.

14:01 Yeah. You got to build that, that magical doorbell robot.

14:05 Right. Maybe selfies for robots or something. They just do it all day long. All right. Awesome.

14:10 All right. So what's number four?

14:12 Number four is called Speed Up Your Python Program with Concurrency by Jim Anderson.

14:17 Oh, this is one that definitely, definitely resonates with me.

14:20 It's, yeah, you have a lot of great material on asyncio and working with parallelism and concurrency

14:27 with Python. And the idea for this article was to give the reader an overview of what different

14:36 types of concurrency that are out there. And what does it mean if a program is CPU bound versus IO bound

14:41 and which options make sense using, you know, when should you use threading versus a multi-processing

14:47 or asyncio. And we also added an interactive quiz to it. So that, you know, if you're reading this,

14:54 you can really make sure, okay, I actually understood these concepts because they're pretty

14:57 difficult to take in the first time.

14:59 Yeah. That's the kind of thing that just needs to wash over you several times until you're like,

15:03 all right, I'm starting, I'm starting to get the feel of this thing.

15:05 Yeah. Get burned by it a couple of times and you're like, oh no, I got to re-architect this again.

15:09 Exactly. And I think this is important in Python because I think Python's concurrency story

15:14 is both amazing, but non-obvious in some ways. And what I mean by that is a lot of programming

15:21 languages, you can leverage computational concurrency by using just threads, right? Because I got, you

15:27 know, this thing believes it has 12 threads in my MacBook here. It has six hyper-threaded cores,

15:32 right? So if I were to like write a single-threaded program, it'll get like eight or 9% CPU usage

15:37 and that's it. So if I want to make that go faster on a lot of languages, C++, C#, whatever,

15:41 I can just create a bunch of threads and it can start running on all of those different threads.

15:45 But in Python, we have the gill, so it doesn't work, right? And that's, I think, actually caused a lot

15:50 of challenges because people say, well, that means Python's concurrency is broken. It's not broken.

15:55 It just needs a clearer mental model of when to apply each technique.

15:59 Yeah. It's kind of like a manual gear shift, right?

16:01 Yeah. Yeah.

16:02 It's not broken, but the car is also not going to go.

16:04 It drives in the day, but it won't drive at night. Put it in night mode. It won't go.

16:09 Put it in N.

16:11 Yeah, exactly. So for example, if it's IO bound, probably what you want to do is something

16:17 to do with asyncio, right? But if it's computational, you really need to do, at least for the moment,

16:22 something with multiprocessing.

16:24 Yeah.

16:24 And so it compares those types of things, huh?

16:26 Yeah, exactly. And like I said, you know, we have this quiz at the end that you can take

16:30 and then really make sure, okay, I understand what the differences are between these concurrency

16:35 models.

16:35 This portion of Talk Python to Me is brought to you by Linode. Whether you're working on a personal

16:41 project or managing your enterprise's infrastructure, Linode has the pricing, support, and scale that you

16:47 need to take your project to the next level. With 11 data centers worldwide, including their newest

16:52 data center in Sydney, Australia, enterprise-grade hardware, S3-compatible storage, and the next-generation

16:59 network, Linode delivers the performance that you expect at a price that you don't.

17:03 Get started on Linode today with a $20 credit and you get access to native SSD storage, a 40-gigabit

17:10 network, industry-leading processors, their revamped cloud manager at cloud.linode.com,

17:15 root access to your server, along with their newest API and a Python CLI. Just visit talkpython.fm

17:22 slash Linode when creating a new Linode account and you'll automatically get $20 credit for your

17:27 next project. Oh, and one last thing. They're hiring. Go to linode.com slash careers to find

17:32 out more. Let them know that we sent you.

17:34 Number five.

17:37 All right. Number five. Build a recommendation engine with collaborative filtering by Abinaf

17:43 Aitzeria. And what do you think this is?

17:47 I'm reading a real Python article and it says, you might also like these other three or something

17:53 like that or talk Python course. You might also like this one, right? It's a good follow-on

17:57 for various reasons, right? People who took this course usually took that one next or people who

18:01 read this article also like shared that other article or something.

18:05 Yeah, exactly. It's about building a recommender or recommendation engines like you would have on,

18:10 you know, pretty much any larger website like Netflix or Amazon. They're all recommending you

18:16 products or movies that you might enjoy based on what you already watched. And a lot of times what

18:22 they do is they look at, kind of build a profile of the things that you watched and then kind of

18:28 finding similar users, other users on the platform that watched those movies and enjoyed them. And

18:33 then based on that, trying to figure out, okay, what did these other people also watch and enjoy?

18:37 And maybe we can recommend that back to you and then hopefully you'll have a good time on the

18:40 platform.

18:41 Yeah, that sounds really cool. It sounds like very relevant to data scientists and there's probably

18:45 a lot of data science algorithms in there, huh?

18:47 Yeah, absolutely. I think there's some cool stuff happening there and there's some matrix math.

18:51 What I like about this article that I really like how it turned out from like a typesetting

18:56 perspective. So that was like a really big aspect of kind of building the new real Python

19:01 CMS and hosting platform and built on Python 3, Django 2 and all the good things. It was a lot of fun

19:07 building it and working on it. And I mean, I'm still working on it. And I think this is just a cool

19:12 showcase for that also, you know, where you get some graphs in there, you get some interactive,

19:16 or you get some code snippets that you can copy and paste and you get some math typesetting there.

19:21 And I think that makes it very engaging to the reader as well. And yeah, and it's just a cool

19:28 topic. Like I'm just fascinated by those things, you know, how you can use the wisdom of crowds or

19:33 whatever that way. You know, you could say like, well, we have enough people using the platform,

19:36 you have enough people watching Netflix. And then all of a sudden I can get these amazing

19:40 recommendations for other things I would have never thought about watching.

19:42 Yeah. You help it make it better for other people without even knowing it, right?

19:45 Yeah.

19:45 Your actions are there and used for good. Yeah. So it talks about things like K nearest neighbors

19:50 and probably the fundamental algorithm there that's being used, right?

19:55 Yeah. I believe it's for this particular recommendation system technique called collaborative

20:00 filtering. But there's also other approaches that I can't really speak intelligently about.

20:06 Yeah, sure. There's even some cool recommendations like the surprise recommender system, which is a

20:11 Python scikit-learn extension, right? So you can install scikit-surprise.

20:17 It's a cool name for recommender system.

20:19 That's a great recommender, right? Like surprise, we actually can recommend something useful. This is

20:23 not like wasted space here. Yeah.

20:26 Cool. Yeah. So if people are interested, they can check that out. And also I noticed it's kind of

20:31 got this bimodal way of working which says, well, if you want to use pip, here's how you do it. If you want to use

20:35 Anaconda, here's how you use that as well, right? So this one seems like there'd be a lot of folks

20:40 using Anaconda as their Python distribution to work on this.

20:44 Yeah. I think if in the data science space, Conda seems to be quite popular. And so typically we kind

20:50 of standardize like for the articles, we standardize on just using pip because that's kind of the lowest

20:54 common denominator. Yeah.

20:55 But in this case, you know, we felt like it makes sense to be closer to where the target audience might

21:02 be there. Right, right. Take it to the data scientists, right?

21:04 Yeah.

21:06 That's really cool. So I love it. It's a good one.

21:08 Number six on our list here.

21:11 Right. So this one might be a bit surprising, but it is called Your Guide to the Python Print

21:16 Function.

21:16 And this is the one that I was talking about when I thought like, okay, I'd know this thing.

21:20 Yeah.

21:21 Like, wait a minute, maybe I don't know this thing.

21:23 So this is more like a book about the Python print function by Bartosz Zaszinski. And this is just this

21:33 incredible deep dive into the print function slash print statement in Python 2. Because again, you know,

21:39 would think, okay, maybe this is maybe a paragraph or two about what you can do with the print function.

21:43 You know, you can pass some arguments to it.

21:45 It requires parentheses now. It didn't used to.

21:47 Exactly. Right. Like what else is there to say? And then it goes really, really deep into the

21:52 history of the print function and some common use cases that maybe you might not associate with the

21:58 print function directly upon first glance. You know, for example, well, how can you build a cool

22:03 console user interface? How can you do colors in the terminal? And how can you pretty print if you

22:10 have a nested data structure, like some JSON that you parsed into dictionary? How can you make sure

22:14 it actually looks good when you print it out to the console or some debug window? And so it's not

22:20 just purely about the print function, but all the kinds of different best practices and ways you can

22:25 make printing better in your Python programs.

22:28 Yeah, that's cool. No one wants to try to use a minified dictionary for debugging.

22:33 Nope. That's very annoying. I usually take those and then paste them into the black online

22:39 format. I get like a nicer representation. Yeah. Yeah. Yeah. So we cover some of the things I

22:45 think are actually not super obvious to new folks coming from the language, right? Like

22:50 that's right. If you come from other languages, you might not know that you can actually use a

22:55 keyword argument to set the end to be instead of a backslash end to be like a comma and print on one

23:01 line with a bunch of commas or something like that or the buffering, right? If I'm trying to do

23:06 something computational and print out as the computation is happening, a lot of times that

23:11 can get buffered up and then it like all shoots out at once. Or, you know, like if you're like

23:15 delaying waiting on something, you want to actually see all the output. Like there's a bunch of little

23:19 tips like that in there, right? Yeah. Yeah. And like with everything, it's there's a deep rabbit hole.

23:24 Yeah. Down the rabbit hole you go, right? Yeah. I love this kind of article where you think, okay,

23:30 we're going to scratch the surface here a little bit and then we're done. And then there's all kinds

23:34 of interesting other things you could do or just learn why certain things work the way they do. You

23:40 know, ANSI or ANSI escape sequences for making the making colors in the terminal. When you read about

23:48 them, they kind of looks like this incredibly confusing format. And then you learn a bit more

23:52 about the history and you know how it relates to the sort of these old school terminals of the old

23:57 like mainframe computers and how, you know, it's just a format that has grown over decades. And

24:03 well, sure, we could all, you know, throw it away and maybe engineer something from scratch. But it's kind

24:07 of cool to understand, you know, if I'm, if I, I don't know, you know, boot up my Windows computer or

24:12 MacBook in, in 2020, why it's still supporting that stuff and how it goes back, you know, 50 years.

24:18 Yeah. Well, another thing that I think makes a night and day difference for these simple little

24:23 command line apps is color. More of those should use color, right? If you're saying in the help output,

24:29 it would be great to show the required arguments is like one color and the optional ones is another.

24:34 And it's incredibly easy. But if you don't know to do it, or you think it's hard, or it's hard to do

24:40 cross platform or whatever, then you won't.

24:42 Yeah. Yeah. Oh, speaking of color there in the terminal, one of my favorite tools is the B Python

24:47 REPL.

24:48 B Python?

24:49 B Python. So the letter B, and then Python, one word. It's a Python interpreter, like a Python, not an

24:56 interpreter, but a REPL environment. That is just like the when you start Python from a command line,

25:01 you get your little prompt and you can type a Python code into it and run it. But it does

25:05 syntax highlighting. So it'll give you beautiful colors in the terminal.

25:09 Nice.

25:09 And it also does autocomplete, which is kind of cool.

25:12 So we use that all the time in our video courses and examples. And people always ask like,

25:18 oh, what's that? What's that tool? I want to use that too. And it's great. Like,

25:21 like the color really adds a lot of value.

25:23 It adds a lot. Yeah. I maybe, I think I've heard of B Python. I haven't used it. I'm all about the

25:27 PT Python. Are you familiar with that?

25:29 Oh, that's great too. Yep.

25:29 Yeah. It's like Emacs in the REPL kind of. Yeah. It takes me back to my Emacs days. So last thing,

25:36 like we go on and on about this, like incredibly for a really long time about printing. But there's

25:41 one thing that's in here. I think that's, that's pretty interesting that they talk about that I guess

25:45 also surprised me. I didn't really think about it is mocking the print function for unit tests.

25:50 Yeah. That's a kind of a surprise, right? But it's, it's actually a pretty annoying problem. If you,

25:56 if you want to write tests for a program where in the test, you actually want to make sure it's

26:00 printing the right stuff. Well, how do you do it? You know, how can you actually redirect that output

26:04 into some kind of buffer so you can inspect it and say, okay, we got the output that we wanted.

26:09 I called this and it said, enter this or whatever, right? Like the prompt that we were expecting or

26:14 something. Yeah. Yeah. Yeah. Yeah. Pretty cool. All right. Well, let's move on because it is the

26:20 print function, but it is actually really, really interesting. And what are we up to number?

26:24 I am trying to check. I think number seven, this is number seven. Yes. Number seven. Yeah. And it

26:30 goes right along to number eight in a sense. So how to write beautiful Python code with PEP 8.

26:36 Yeah. So this is a cool article by Jasmine Feiner and it's about the PEP 8 style guide and sort of

26:44 a beginner friendly intro to PEP 8, why it exists, how it can help you format your code in a way that

26:51 other Python developers will expect and appreciate. And I think it's, it's a really good one because,

26:58 you know, it breaks it. Like if, when you read the actual PEP 8 can be feedback that I heard in the

27:04 past, it's just very, very overwhelming to take it all in and take all the examples in. So we try to

27:08 break it down and give you a good overview and then point you to the original PEP so you can do the deep

27:15 dive. Yeah. It's really cool. And you know, it's one of those things that's really important that,

27:20 so you look like you belong, right? If you start doing stuff that is, you know, Java style or C#

27:28 style and someone says, yeah, I'm interviewing for a Python job. And here, let me write a little

27:34 code for you and you start using like camel case method names or something like that. You're like,

27:40 not so sure you're a Python developer. You don't look like you're from around here, right?

27:45 Yeah. First impressions matter, I guess.

27:48 Yeah. And you know, once you know the conventions, some of those conventions have meaning,

27:52 right? Like the underscore has a certain meaning and things like that. And so it's not implicitly

27:59 obvious from that thing that what the meaning is. But once you study it, then you get to know,

28:04 right?

28:04 Yeah. Yeah. I'm actually, I wanted to ask you what's, is your talk Python, is the code for the

28:09 talk Python platform? Is it PEP 8 compliant?

28:11 Is it PEP 8 compliant?

28:12 It's both for the platform it is, I would say PEP 8 compliant. And I try to do that in the courses.

28:18 Probably the way I do that most is just running, like working on everything in PyCharm and PyCharm

28:24 will highlight stuff and make it obviously, it'll like, as you type a highlight, it'll go, no,

28:29 no, no, no. There's something clearly wrong. Like you don't have an underscore, you have camel case

28:33 on a variable name. Stop doing that. Right. And so, yeah, I don't run anything like black across

28:38 the whole thing. The only thing I've run entirely across the whole code base, not across the courses

28:44 because it's recorded. So it'd be weird to change it. But in terms of the platform, I've used Flint.

28:49 Are you familiar with Flint?

28:50 I feel like I heard about it. Is this another auto format?

28:54 It has, it's a very special tool, but I love it. What it does is it will take all the various string

29:00 formatting styles of working with strings. So percent, value value, or the format, something

29:08 or other, and so on. And it turns on all the f-strings.

29:10 Oh, that's cool.

29:11 Yeah. It'll just rewrite your code, like rewrite all your f-strings.

29:14 I know a certain core Python developer who would love that. Marietta.

29:17 She does all these awesome stickers.

29:20 Yeah, yeah. Yes, man. Yeah. So I ran it. In the early days, it had a couple of bugs when you were doing

29:26 numerical formatting, like this number, comma, colon, comma, like 0.2F. Like that would get freaked out.

29:34 But yeah, like after a couple of iterations, it's really quite good.

29:37 Oh, that's cool. I think, yeah, I got to run that. That's great.

29:40 Yeah. So I just ran it against like 20,000 lines of code across the training site and the Talk Python

29:44 and Python Bytes websites. And I think there was like maybe one mistake. So I just,

29:49 I looked at the diff before I checked them all in and just said, actually this, you know,

29:52 one out of a thousand, there's this mistake. But yeah, yeah.

29:55 I think actually those are probably pretty much gone. But yeah, anyway, and it's not PEP8, but it's a sort of a continuation.

30:00 Yeah. And I think with this stuff, I feel like we've got to be clear, like it can often be ambiguous,

30:05 right? Like any, any sort of code style guide, like PEP8 or what have you, you know,

30:09 in other languages, it's usually not at the end of the day, like naming is a big part of a

30:15 developer's job, I think, you know, and in picking names that are actually communicating the intent well and other people can understand.

30:21 And so it's, it's, it's not going to solve that problem because, well, even though if,

30:26 you know, if you're following PEP8 to a T and you're using all the upper and lowercase letters

30:30 in the, in the right way, and your naming isn't, just doesn't make sense, then that's also not

30:35 going to be great. So it's, yeah, another example might be struggle.

30:38 Yeah. You're doing a list comprehension and it's all on one line, right? It's got the,

30:43 you know, and for N and such and such, if N such and such. And it happens to be 79 line characters

30:49 long. So it's on column 79. It's fine. You don't need to wrap it, but it's like super hard to

30:54 understand. It would make sense to have that three lines, the select value, the loop, the,

31:00 the collection is going through and the, the test, right? It would be much better. But PEP8 doesn't say,

31:04 well, if it's 79 lines and complicated, it should be broken up. But 80 lines is, you know,

31:10 like the hard limit and things like that, right? Yeah. Yeah. And so we've got to think beyond it.

31:13 Are you following the 79 characters limit in your code basis?

31:17 Do I follow? Sometimes. There's a few times where I don't like, so if I have a, a raw string or

31:24 multi-line, not raw string, a multi-line string where you do triple quote, then like there's a bunch of

31:28 stuff and then triple quote to close it. I don't know of a way to not do more than 80 lines. If what needs to

31:33 be in the string is more than, or 80 columns, but he would still complain to me like, oh no,

31:37 this line is 120. I'm like, yeah, but you show me how to fix it and we'll have a conversation,

31:41 but I can't fix this, right? Yeah. Without completely going, you know what, we're going to have a string

31:45 concatenation like to nobody's end rather than this multi-line string. So there's a few edge cases,

31:51 but I try to. Yeah, me too. Like ever since I started using black, you're like, black's going to change

31:55 it anyway. I think you can tell it like to use a different line length limit. Like I feel like that's,

32:00 that's always something that comes up where it's like a kind of controversial topic where should

32:05 you follow the 79 character limit is even another, there's like a 72 character limit recommendation

32:10 for doc strings. Like I try to follow that as well. I have like my, you know, these like a little,

32:15 little gutter margin set up in the editor. So yeah, exactly. That's cool. But then at the,

32:19 sometimes I'm thinking, okay, but wouldn't it be nice just to go a hundred characters or longer?

32:22 So I think, I think like whatever number of people pick, as long as you're consistent,

32:25 it's, it's probably a good thing. Yeah. It's somewhat contextual.

32:28 This portion of Talk By The Enemy is brought to you by Brilliant.org. Let me knock something off

32:35 your holiday to-do list. Gifts. Spread the love to your loved ones by gifting them Brilliant.

32:41 This really excites me because it's such a fun way to nurture curiosity, build confidence,

32:46 and develop problem-solving skills crucial to school, job interviews, or to their career.

32:50 Brilliant's thought-provoking content breaks up the complexities into bite-sized,

32:55 understandable chunks that will lead them from curiosity to mastery. Go to talkpython.fm

33:01 slash brilliant and grab a gift subscription to help your loved ones finish their day a little

33:06 smarter this season. That's talkpython.fm/brilliant, or just click the link in the show notes.

33:13 We talked about Pep 8. Now how about Article 8? Article 8 is about the Python Lambda function. So it's called

33:21 How to Use Python Lambda Functions by Andre Bourgo. And yeah, I wanted to highlight this one because

33:28 Lambdas and Python are a topic that can be challenging. I think it's something that a lot of times you don't

33:37 really have to, you don't really work with. And so you don't get a lot of experience working with it.

33:41 And then when there might be a situation where it's actually useful, for example, if you want to

33:45 sort a list or something sorted by a custom key, then if you don't know about Lambdas,

33:50 it's going to be a frustrating experience.

33:52 Right, right. Like I got to write this other function and that's kind of weird. But yeah,

33:56 so they're one of the things that when you learn them, you're like, man, that is cool. I can't

34:01 believe I can think of immediately 10 places I would use this, but they're not obvious that they exist

34:06 or that you could use them until you see them, right?

34:07 Yeah, that's right. And it's, what's the quote there? Like the dose makes the poison or what?

34:12 I only know the German version.

34:14 Yeah.

34:15 Die Dose macht das Gift.

34:17 Yeah.

34:18 So the dose makes the poison.

34:19 Yeah. Basically you don't want to, you want to apply it. It's like salt, you know, you don't

34:24 want to overdo it with the salt because then the food's going to taste it.

34:27 Yeah. Yeah. A pinch will do you. Absolutely. So yeah, that sounds about right.

34:31 Yeah. And so, so this article goes into some use cases and also into the kind of the language

34:37 history or why are these types of functions called lambda functions and how does this relate to this

34:44 thing called lambda calculus that was invented in the 1930s. And we go back into some of the computer

34:50 science stuff.

34:51 Yeah, that's cool.

34:52 So you can also learn about that.

34:53 You know, another thing that I think is interesting that gets very little attention,

34:57 I suspect this is happening to a non-trivial number of people and they don't even know is closure.

35:03 Right? So closure is the idea that like I have a variable that's either available in the local

35:08 method or it's a global variable. Most likely it's like a local variable on that method.

35:14 We're using the lambda and you say it in the function body, the lambda body, but not as an argument.

35:22 Right. It's somehow magically.

35:23 Kind of capturing that.

35:25 Yes.

35:25 I find this so hard to explain just in audio only because when you see it with an example,

35:30 like in the article, it's to me at least a lot easier to wrap my head around it.

35:35 But yeah, let's give it a shot.

35:37 Like can we.

35:37 Yeah. Well, some really interesting stuff happens with closure, right?

35:41 It's not just that the variable is like passed, but it's remembered.

35:46 It's remembered across function calls.

35:49 So even if you change it and then you call the lambda again, it will work with not the

35:53 original value like a compi, but it'll work with a changed value.

35:56 Which can really bite you also if you're referring to a mutable object and you think you've kind

36:02 of captured the full state of this object and then it gets changed under you.

36:08 which I think this is also kind of maybe the danger of using lambda is that if you don't

36:13 understand how closures work or when that effect kicks in, that you might be writing code that

36:21 actually breaks under unexpected circumstances.

36:24 Yeah.

36:25 And it can be incredibly hard to understand why if you have no idea that this is happening.

36:29 On the flip side, you can use it for great power as well.

36:33 Like let's just go to like something super simple.

36:35 I want to sort a list.

36:36 I want to say key equals lambda of item, colon, do something with the item, right?

36:43 But maybe there's other variables or other data that's in the function that you want to use to

36:50 decide how you sort.

36:51 Like if it's below this cutoff, I want it first.

36:54 But if it's after this cutoff or like, you know, it's somehow you've got to compute with some other

36:59 data that's not purely just the item.

37:01 Like if you wanted to sort, you had an address book with, I don't know, name and year of birth

37:06 and you wanted to sort it by some calculated value.

37:10 Yeah.

37:10 So like both of them.

37:11 Right, right.

37:12 So if they don't have a date of birth, you could have like, here's the default date of

37:15 birth we're going to use.

37:15 Right, yeah.

37:16 Right, right.

37:16 Substitute something.

37:17 Yeah, they're all going to be born in 1970 or something.

37:19 Who knows?

37:19 So you could like have that as a local variable, but then include that in your sort lambda.

37:24 But the function that's getting called, it only takes the item and the list doesn't know

37:30 about your need of this other variable.

37:32 It's not going to pass it in, but you can just use closure to just capture it and just like

37:36 bring in more arguments into your lambda than would otherwise be available.

37:40 And that's a super powerful thing you can do.

37:42 Yeah.

37:42 Yeah.

37:42 I think that probably the main use case, what I personally use them for, there's also

37:47 a section in the article that talks about whether lambdas are, we can consider them pythonic

37:53 or not.

37:54 Because in PEP 8, which we just talked about, there's actually a recommendation there that

37:59 says you should always use a def statement.

38:02 So define a proper function instead of an assignment statement that binds a lambda expression directly

38:07 to an identifier.

38:07 And so this is like a strong discouragement to using lambdas.

38:11 I think mainly when you actually, you want a named function.

38:15 I think anytime you actually want a named function, you should probably not use a lambda.

38:18 But if it's like a one-off thing, that's where I would use it.

38:22 Yeah.

38:22 You even talk about in your article a little bit, like anonymous functions, meaning they

38:26 have no name.

38:28 You're passing them somewhere.

38:29 You're modifying the behavior like of the sort or whatever, but you're not naming the

38:34 thing doing that.

38:35 Yeah.

38:35 That's right.

38:36 And with great power comes great responsibility.

38:40 That's right.

38:41 I think one of the key essence of the lambda, like decide, should I make a separate function

38:47 or should I make a lambda function?

38:49 I think one of the key differences here, or the key decision, at least for me, is, is it

38:54 going to be clearer to just plunk the implementation right here than to give it a good name and put

39:01 it somewhere else?

39:01 So if it made a lot of sense to give it a good name and put it over there, because it's kind

39:05 of complicated, but the name tells you what it does and then use that as the sort, great,

39:10 do that.

39:10 But if it's like, I'm going to sort just by like sort of list of customers, it's just

39:15 lambda of C colon goes to C dot name.

39:17 Okay.

39:18 Like it would be more confusing to move that away because then you have to be sure like

39:22 sort by name.

39:23 You're like, oh, wait a minute.

39:24 Descending or ascending?

39:25 Well, it used to, they renamed it to say sort by name ascending, but then they actually changed

39:29 implementation to descending, but they forgot to rename it because they're afraid to break

39:34 the code.

39:34 And just like, there's all sorts of weird stuff if you move it away.

39:38 So if it's clearer to have it like in line than lambda, otherwise not lambda.

39:43 That's my test.

39:45 That's a good rule of thumb.

39:46 I feel like I mainly use lambdas for exactly that, that use case and otherwise try to stay

39:51 away from them.

39:52 If you have to line break a lambda, that's a problem.

39:54 Yeah.

39:54 Yeah.

39:54 That's, yeah.

39:55 That's maybe also a good heuristic, right?

39:57 Where, yeah.

39:57 Yeah.

39:58 You could only have, you know, basically you can just put an expression into it.

40:01 So that's the other thing that we haven't even talked about.

40:03 So they're also limited in what you can actually put into a lambda function.

40:06 Right.

40:07 So you can pretty much just have a single expression that would also be the result of which will

40:12 also be returned as the return value of that, of that function.

40:16 And that also limits you, but of course you could use all kinds of ugly work to do something

40:23 that you're not really supposed to do with them.

40:26 Exactly.

40:26 Exactly.

40:27 But you can't have multi-line lambdas in Python, whereas you can in other languages.

40:31 Like for example, C# has lambdas.

40:33 They're basically the same idea, closure and all that, but you can put curly braces and make

40:37 it 20 lines long if you think that's a good idea.

40:40 That's like a great idea.

40:41 JavaScript's kind of like that, right?

40:43 You can like function curly or parenthesis argument and then just curly braces, right?

40:48 So to tell you a secret, I feel like what forced me to understand closures was doing more JavaScript

40:56 development because you cannot avoid them.

40:57 Yeah, closure's all over the place in JavaScript, right?

40:59 Yeah.

40:59 Yeah.

41:00 Yeah, it is for sure.

41:01 And they have like similar ideas.

41:02 They don't call it lambda, but like they have anonymous functions basically.

41:06 Yeah, that's right.

41:07 Yeah.

41:07 All right.

41:08 Are we already at number nine?

41:09 Number nine.

41:10 Number nine.

41:10 There we go.

41:11 Yeah.

41:12 So number nine is about Python coding interviews.

41:15 So the article is called How to Stand Out in a Python Coding Interview by James Timmons.

41:19 And I felt that this is an important topic and it's hopefully also something useful for you,

41:27 dear listener.

41:28 Maybe you have a Python coding interview coming up or you're worried about, you know, when

41:32 the day comes where somebody is going to grill you on your Python skills.

41:35 And we put this article together to cover some common situations there, basically some tips

41:41 that you can use to showcase your deep understanding of the Python programming language.

41:47 Yeah, you've broken into a couple of sections, right?

41:51 You've got like know your built-in functions, know the right data structure, take advantage

41:56 of the standard library, right?

41:57 If somebody says, I want you to use the quick sort, you're like, you know what?

42:01 I created a list.

42:02 Tim sort.

42:02 Yeah, yeah, exactly.

42:04 Or something like that, right?

42:05 Or I think the data structures is super important.

42:08 That's a great giveaway.

42:09 Like I want you to get a bunch of, I don't know, say users and I want you in memory and

42:14 I want you to look them up by ID and I want you to do that quickly, right?

42:18 Like dictionary.

42:18 Yeah, dictionary.

42:19 Does look up quickly happen?

42:20 Is that the question?

42:21 Dictionary.

42:22 Just yell dictionary.

42:25 Dictionary.

42:26 Exactly.

42:27 Or unique or distinct.

42:29 Okay, set, right?

42:30 Yeah.

42:31 Did they say distinct?

42:31 They mean set, right?

42:33 Like just right away, there's, you could have like a complicated 10 line for loop where

42:38 you test, have you seen it before?

42:39 Or set, right?

42:41 Like that's both knowing the built-ins and knowing the right data structures, I think.

42:44 Yeah.

42:44 And it is so much good stuff in the Python standard library or in the core language, you

42:48 know, another great one I think that's worth knowing about is in the collections module,

42:52 the counter class.

42:53 Oh yeah.

42:54 It's if you ever need to count different items or, you know, how often does this string

42:59 or this word occur?

43:00 Right.

43:01 I got a list of text.

43:02 Like a whole bunch of domain names.

43:04 I need to know like how many, each one of them appears.

43:07 Right.

43:07 That sounds like a challenge or it sounds like two lines.

43:09 If you know counter, right?

43:12 Yeah.

43:13 You create a, you import collections, you create a counter, they're most common.

43:16 Right.

43:17 But like these things are incredibly simple when you know them, but if you don't know they

43:22 exist, it's really challenging.

43:24 And I think that's actually a problem from, not a problem, but a, a learning challenge

43:28 kind of going back to your other article.

43:31 I don't remember which number it was, but the one, I think maybe number two about all

43:35 the projects, right?

43:37 Like some of those projects would be really easy if you knew the right libraries.

43:41 But if you thought I have to write this from pure Python from scratch and I've got to implement

43:45 this stuff, right?

43:46 Like, oh, that MP3 player is super hard.

43:48 Like, let me get down to the bytes and look at it.

43:50 Like, no, you pip install like the MP3 library or whatever, like it is that works with that,

43:56 right?

43:56 It's, there's a whole lot of options.

43:58 And I think learning Python is challenging because you learn the language and you think

44:03 you've done it, but you've only like hit the 10%.

44:05 Now you've got to learn the standard library.

44:07 Then you've got to learn everything on awesome Python or PyPI or, right?

44:11 So there's these levels.

44:12 And, you know, but I do think for tests, for interviewing, knowing the foundational stuff

44:17 is most important.

44:18 I agree.

44:19 Yeah.

44:19 And we were thinking, you know, we're going to pick stuff that is actually very likely to

44:23 come up in an interview because in an interview, I think you're not going to get super specific.

44:28 You know, you're not going to talk about the LMHDB or whatever the lightning memory database

44:34 that we talked about earlier.

44:35 That would be, nobody's going to expect, I mean, depending on the kind of role, but if

44:40 it's, if it's data science, they might expect you to know NumPy.

44:43 Right.

44:43 If you've claimed, you know, Python, you better know NumPy at least cursory, right?

44:47 Yeah.

44:47 And if you claim that you, you especially better know about things like the collections module,

44:52 you know, these like core things.

44:53 Yeah.

44:53 Yeah.

44:54 For sure.

44:54 Yeah.

44:55 What about when you get stumped?

44:56 What is your thoughts on like, you know, how do I do this thing?

45:00 Like, you know, inside your thing, screaming, like I have no idea.

45:04 Yeah.

45:04 I start sweating profusely and shivering.

45:07 Go into the fetal position.

45:09 That's why I'm running my own company now.

45:11 Yeah.

45:13 No, that's a tough one.

45:14 I think the advice that I would give is start asking questions because it's oftentimes not

45:20 a good sign if you ask someone a question in an interview setting and they immediately launch

45:24 into writing code or they feel like they're expected to know the answer off the bat.

45:28 A lot of times what the interviewer will want to see is how are you approaching a problem?

45:33 Are you able to get help?

45:34 Are you able to ask intelligent questions?

45:36 And even if you don't know the specifics, I mean, nobody really expects that, right?

45:40 A lot of times if you can use Google, if you can use Stack Overflow, if you can use, you

45:43 know, Talk Python and RealPython and all these sites that are available to you, you would have

45:48 that in your normal working environment.

45:50 You know, like I use Google and Stack Overflow like probably like hundreds of times in a productive

45:55 day.

45:55 I use it shamelessly without guilt or judgment, right?

46:00 I mean, because there's a bunch of stuff that you need to know and then there's a bunch

46:03 of stuff that just doesn't deserve to take up space in your memory, right?

46:08 And you should just be able to go, I'm just going to Google it.

46:11 I don't know what the right way to do this library with that thing is.

46:14 I'm going to Google it.

46:16 But just like actually knowing that it exists and I just don't remember quite how to use

46:19 it, I think is like the big step.

46:21 Like I know I know there's a counter thing and I know I can get it to group by the count.

46:26 I just don't remember how to the steps to make that happen, right?

46:30 Like I think that's okay.

46:31 Yeah, I think that's totally okay.

46:33 So just duck, duck, go it.

46:35 Just bing it.

46:36 Google it.

46:37 Just duck, duck, go it.

46:39 AltaVista it.

46:40 I don't know what else is there.

46:41 Yahoo it.

46:42 Yeah, yeah.

46:42 AltaVista.

46:43 That's a good one.

46:44 I remember that.

46:44 That was good.

46:45 One other thing I would sort of put out there is like a huge turnoff to me if I was

46:50 interviewing, I did that for a while with people.

46:52 If I feel like they are lying to me, they're done.

46:55 I don't care if they seem good.

46:57 If I say like, oh, how would you do that with SQLAlchemy?

47:00 Oh, like I've used so much SQLAlchemy.

47:02 And then you can tell like they've never, ever, ever seen it, right?

47:06 Like they don't even, they can't even describe like, well, what I would do is create a class

47:09 that derives from like another class and it maps to the database.

47:12 Like that's a foreign idea.

47:14 But they're claiming like they've used it in production.

47:17 Like done.

47:18 Not a good strategy.

47:19 Not, I would, I don't know.

47:20 How do you feel?

47:21 Like, would you hire that person?

47:22 Because everything else comes to the question, right?

47:24 I agree.

47:25 It's, it's, yeah.

47:26 It's at that.

47:26 You want to find, find out, would you ask the interviewer?

47:29 I feel like you also want to find out, would you want to have this person on your team?

47:33 Would you want to work with them?

47:34 Right.

47:34 Would I trust them to be?

47:36 Yeah.

47:36 They start making up stuff like, hey, you know, did you review that pull request or request?

47:40 Or did you merge that hot fix?

47:42 Or did you, I don't know, do that?

47:43 And then you feel like you can't really rely on that person and it's not a good start.

47:47 Or we're going to build an e-commerce backend.

47:50 Who's done payment stuff before and feels like they can do it, right?

47:53 And maybe not.

47:54 I don't know.

47:55 Definitely use floats for currency.

47:56 Yeah.

47:58 I don't know if we have that one in the list, but that's, that's also a really common question.

48:02 I feel like where people are like, oh, what data type should you use to represent currency

48:06 in your program?

48:06 Right.

48:07 Right.

48:07 Integers probably.

48:08 Yeah.

48:09 Yeah.

48:09 And then break it down to sense and then use integers.

48:11 Yeah.

48:12 Just round it.

48:13 Just round it.

48:13 Just round it.

48:13 About a dollar.

48:15 Yeah.

48:16 It's all good.

48:19 It's about a dollar.

48:20 All right.

48:21 Well, we're coming up on the, the grand finale here.

48:24 And this is another one that I could, I'm very passionate about.

48:26 I could riff on for a long time.

48:28 So you'll have to stop me at some point, but it has to do with the object oriented programming

48:33 component of Python.

48:35 Yeah.

48:36 So the article is called inheritance and composition, a Python OOP guide by Isaac Rodriguez.

48:42 And I think inheritance and composition, that is the, one of the core pieces of object oriented

48:50 programming.

48:50 And in my experience, it's also the piece that if you're completely new to OOP and you're trying

48:56 to understand, okay, well, how is this helpful?

48:58 Like how does this work?

48:59 It can be a sticking point for some people.

49:01 Yeah.

49:01 So we wanted to do a dedicated article that is, yeah, basically a deep dive on inheritance.

49:05 It sounds a little bit like modeling with objects and just like some practices around

49:10 that.

49:10 Right.

49:11 Yeah.

49:11 And how do you go about like breaking down a hierarchy or like, I guess a domain into a

49:17 hierarchy of objects?

49:18 Yes.

49:18 Yeah, exactly.

49:19 That was getting at.

49:20 And so maybe we should define inheritance and composition.

49:23 I think inheritance is pretty clear.

49:25 Composition might be a little less well known.

49:27 So inheritance is, I want to model like a bunch of cars.

49:31 So I have a basic car or just a car, but then I have a sports car that does sporty things,

49:37 right?

49:37 Maybe it has like paddle shifters or it has like a manual transmission mode that has additional

49:42 functionality.

49:43 So I might say, all right, well, the idea is what we're going to do is we're going to

49:46 create a car and a sports car.

49:48 And then maybe I want to have a track car that can also take slicks.

49:51 Like, so it derives from sports car.

49:53 And the deeper that those get, the more full of the abstractions can break down pretty hard,

50:01 right?

50:01 Like, you know, if you model creatures, I've got a living animal and then I've got a bird

50:07 and then I've got, what do you do with a robot bird, right?

50:11 Does it drive from bird?

50:12 That's a hard one.

50:13 Right.

50:13 Like it, it has bird like things, but the animal eats, robot doesn't eat.

50:17 Right.

50:18 So like if you go too deep, it makes, it's a problem.

50:20 Right.

50:20 So that's inheritance, obviously.

50:22 Composition.

50:23 Tell us about it.

50:24 So composition.

50:24 So if inheritance defines is a relationship.

50:27 So like a sports car is a car and the car is a vehicle and a vehicle is a thing or whatever

50:33 machine.

50:33 Composition defines a, has a relationship.

50:37 So you can say, okay, a car has an engine or a car has a steering wheel.

50:43 Right.

50:43 And it has a transmission.

50:44 Instead of making a sports car, maybe you just make a car with a sporty transmission.

50:49 Right.

50:50 And so the whole thing doesn't have to like, because I don't know, what if you have some

50:55 kind of truck, but it also has like a manual shifting thing, right?

50:58 It could, right.

50:59 You wouldn't have a truck derived from a sports car.

51:01 That would be weird.

51:02 Right.

51:02 But you could easily like interchange the parts and it, it helps really alleviate some

51:07 of those like deep object hierarchies.

51:10 I think.

51:10 Yeah.

51:11 Yeah.

51:11 It's, it's basically another tool in your toolbox there for defining these relationships.

51:15 Because if, if you define everything in terms of a inheritance relationship, then you end

51:19 up with these unmaintainable, like the, you end up on the dark side of OOP.

51:24 That's right.

51:25 And like small changes to like a deep down base class can make absurd things in the end, like

51:32 a robot that has to eat or something like that.

51:34 Cause maybe the animal didn't eat at first and that made sense.

51:36 But now later you realize all the animals have to eat.

51:38 And then like, well, what do you do about the robot thing that we put there?

51:41 Like that's where you use multiple inheritances, which is like a whole dutter of can of worms.

51:46 That's a deep, that's a big can of worms as well for sure.

51:48 But I, I'm a big fan of composition.

51:50 I think, I can't remember where I heard, I'm pretty sure the original gang of four design

51:54 patterns books said prefer composition over inheritance.

51:57 Yeah.

51:59 Like you want shallow hierarchies.

52:00 Yeah.

52:01 Like you're going to like it's objects and inherits aren't inherently bad, but they're

52:05 easy to abuse.

52:06 And so composition is a really way, good way to keep those shallow and interchangeable and

52:11 small.

52:11 So yeah, quite, quite cool.

52:13 I like this one a lot.

52:14 Wow.

52:15 Did we really make it to the, all the way?

52:16 Oh, actually speaking of the gang of four book, I think that might be a recommendation

52:20 here at the end of the article because we, yeah.

52:23 Also always give.

52:24 Yeah.

52:24 So the article comes with recommended reading, right?

52:26 Yeah.

52:27 Yeah.

52:27 It's got some cool design, design patterns.

52:30 head first design patterns, clean code, solid principles, list cove substitution principle,

52:34 all those kinds of things.

52:36 Yeah.

52:36 A lot of these apply.

52:37 It would be remiss of us, I think, to riff so fondly on like an object oriented story in

52:44 Python without seeing that like a lot of what people do with objects and classes and other

52:50 languages is simply unnecessary in Python.

52:53 Right.

52:54 So there is a little bit of pushback and well, I know you did Java and everything had

52:58 to be a class.

52:59 You don't have to build it this way.

53:01 Right.

53:01 Like for example, if you have a variable that you need to be basically a singleton and then

53:07 you want to group a bunch of functions together, you could have a static class that has those

53:11 in there in like Java or C# or something like that.

53:15 But you could also in Python just have a module that has a variable and it has functions.

53:21 And then if you just import that module, you say that module dot the, the fields or the

53:26 variables or the functions, that's the same thing as a static class.

53:29 Right.

53:30 Yeah.

53:30 Right.

53:30 You don't have, and you don't, it saves you a bunch of work and it's, it's more Pythonic.

53:35 Yes.

53:35 I guess.

53:36 Right.

53:36 Then making everything a class.

53:38 Yeah.

53:38 So there, I mean, maybe there's a little bit of, do I really need a class for that?

53:43 Right.

53:43 If you're going to create different ones over there, different values at the same time, like,

53:47 well, probably.

53:47 Right.

53:48 But maybe if you're like just trying to group stuff, maybe the modules, right thing.

53:50 But if you do decide and it does make sense to have a class, this inheritance versus composition

53:56 thing is super important to understand.

53:57 Yeah, absolutely.

53:58 And I don't want to give the impression that like, you know, if you, if you're writing in an object

54:02 oriented programming state style, that that's somehow superior or like the end

54:05 all, you know, of, of coding.

54:07 I don't, I don't think that's, that's actually true.

54:09 I think the, the really powerful thing is understanding these tools, like to have a really

54:13 big toolbox and being able to pick the things that make the most sense.

54:17 Like a lot of times, you know, when, when I'm writing a program in Python or I'm sketching

54:20 something out, I, I'll hardly like write any classes depending on, on the use case.

54:24 Or I found myself, you know, most recently just basically adding like these, like, so I've

54:30 been working on the real Python platform a lot and I've been writing more function-based

54:35 codes or procedural code where maybe my data model is class-based, but then I'll have,

54:41 you know, a module or I don't know, redeeming access codes or coupon codes or something like

54:47 that.

54:47 And it basically defines like a really nice high level interview interface to me.

54:50 These are the five operations you do on coupons or something, right?

54:54 Yeah.

54:54 Yeah.

54:54 And that's all function-based.

54:56 Yeah.

54:56 And then internally they, they use classes to kind of represent the data and, and shuffle

55:01 it around.

55:01 Probably working with Django ORM or something like that.

55:04 Right.

55:04 Yeah.

55:04 Yeah.

55:04 Yeah.

55:04 Instead of cramming that all into a view or actually I prefer, for example, a function-based

55:09 views in Django instead of class-based views because I don't like sort of the getting the

55:12 deeper intendation.

55:13 I would, we could, we could get into all kinds of, disagreements there, but, yeah,

55:20 just, just want to make sure, you know, that, that I get this across that, I don't

55:23 think the OOP coding style is, not the one true way that the one true way that this

55:30 should be one, exactly one way to do things.

55:31 Yeah.

55:32 Yeah.

55:32 But if you're going to do it, like understanding this, this difference between inheritance

55:35 composition, certainly, it certainly makes sense.

55:37 I do a lot of what you're recommending there as well.

55:39 All right.

55:39 Well, that's our top 10 items, Dan.

55:42 Yeah.

55:42 That, that went by super fast.

55:45 Yeah.

55:45 It did go by fast, but I think these all have special value and, you know, people might

55:49 be kicking back.

55:51 A lot of folks have vacation time around this time of year.

55:53 You know, they're also thinking of what's coming in the next year in 2020.

55:57 I mean, first of all, let's just take a moment and say, thank you, Python 2, but goodbye.

56:05 Yeah.

56:05 Bye-bye.

56:05 We'll miss you.

56:07 The death plot is down to single digit days probably at this point.

56:12 Right.

56:12 So that's actually pretty exciting.

56:14 Yeah.

56:14 That's a big change, right?

56:15 Yeah.

56:15 Yeah.

56:16 You're right.

56:16 Yeah.

56:16 Cool.

56:17 All right.

56:17 Well, there's a bunch of articles for people to check out while they're on vacation, got

56:21 some time away from work.

56:22 They don't have to, you know, fill out TPS reports all day.

56:24 Smashed out printer.

56:27 That's right.

56:27 Smashed out printer.

56:28 Awesome.

56:29 All right.

56:29 Well, thanks for being here as always.

56:31 Cool.

56:31 Yeah.

56:31 Thanks for inviting me.

56:32 This is great.

56:33 You're welcome.

56:33 I guess I should ask you the two questions before you go.

56:35 So the two questions are, what editor do you use to write Python code these days?

56:40 So I've started to use Visual Studio Code a lot.

56:43 I use Sublime Text.

56:46 Yeah.

56:46 It's a pretty similar style of editor.

56:49 Very similar.

56:49 Right.

56:50 Yeah.

56:50 What I still love about Sublime is just how fast it is.

56:53 Like there's a noticeable difference in the rendering speed and scrolling around.

56:58 But the Python integration that VS Code has out of the box is really cool.

57:05 It's growing and growing all the things it can do.

57:07 I like it for recording video courses because I can have an integrated shell there.

57:12 I can have a setup that looks really, really nice, I think.

57:14 And so I've been doing that a lot recently.

57:16 And so, yeah.

57:17 Working out of VS Code.

57:19 Yeah.

57:19 Awesome.

57:20 The other question changing for today.

57:22 What's next for RealPython in 2020?

57:25 100 authors?

57:26 Yeah.

57:26 That's a big goal of mine.

57:27 You know, I want to, I would love to have 100 authors published on the site.

57:31 Authors and instructors as a magical number.

57:33 And, you know, maybe we'll crack that 3 million visitors.

57:37 I don't know how many Python developers are out there.

57:39 Well, I suspect after they listen to this episode, it'll probably be 3 million straight up.

57:43 It'll be 10 more.

57:44 For sure.

57:46 It's going to, yeah.

57:47 Awesome.

57:47 Well, best of luck in 2020 and keep up the good work.

57:50 It's a huge resource for everyone.

57:51 Thank you.

57:52 I mean, you know, same to you.

57:53 Like, it's been so cool just becoming friends with you.

57:56 And when we first met, which was, I think, like three years ago.

57:59 Three or four years ago.

58:00 It's quite a while back.

58:01 And just being on this journey here together.

58:03 I really appreciate that.

58:05 Yeah, absolutely.

58:06 Thank you.

58:06 Same to you.

58:06 It's been fun to be on it together.

58:08 Awesome, man.

58:08 All right.

58:09 Well, catch you later.

58:09 Bye.

58:10 Yeah.

58:10 Bye-bye.

58:10 This has been another episode of Talk Python to Me.

58:14 Our guest on this episode was Dan Bader.

58:17 And it's been brought to you by Linode and Brilliant.org.

58:20 Start your next Python project on Linode's state-of-the-art cloud service.

58:24 Just visit talkpython.fm/Linode.

58:27 L-I-N-O-D-E.

58:29 You'll automatically get a $20 credit when you create a new account.

58:32 Brilliant.org encourages you to give the gift of critical thought and knowledge.

58:37 Visit talkpython.fm/brilliant and grab a gift subscription to help your loved ones finish

58:43 their day a little smarter this season.

58:44 Want to level up your Python?

58:47 If you're just getting started, try my Python Jumpstart by Building 10 Apps course.

58:51 Or if you're looking for something more advanced, check out our new async course that digs into

58:57 all the different types of async programming you can do in Python.

59:00 And of course, if you're interested in more than one of these, be sure to check out our

59:04 Everything Bundle.

59:04 It's like a subscription that never expires.

59:06 Be sure to subscribe to the show.

59:08 Open your favorite podcatcher and search for Python.

59:11 We should be right at the top.

59:12 You can also find the iTunes feed at /itunes, the Google Play feed at /play,

59:17 and the direct RSS feed at /rss on talkpython.fm.

59:21 This is your host, Michael Kennedy.

59:23 Thanks so much for listening.

59:25 I really appreciate it.

59:26 Now get out there and write some Python code.

59:27 I'll see you next time.

Back to show page
Talk Python's Mastodon Michael Kennedy's Mastodon