Latest / Talk Python To Me / #244: Top 10 Real Python Articles of 2019
Transcript
- 0:00We've come to the end of 2019. Python 2 has just a handful of days before it goes unsupported,
- 0:05and I've met up with Dan Bader from realpython.com to look back at the year of Python articles on his
- 0:11website. We dive into the details behind 10 of his most important articles from the past year.
- 0:16This is Talk Python To Me, episode 244, recorded November 8th, 2019.
- 0:22Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the
- 0:40ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter where
- 0:45I'm at mkennedy. Keep up with the show and listen to past episodes at talkpython.fm,
- 0:49and follow the show on Twitter via at talkpython. This episode is sponsored by
- 0:54linodeandbrilliant.org. Please check out what they're offering during their segments. It really
- 0:58helps support the show. Hey there. I want to take just a moment before we get to the interview
- 1:03and say thank you. It's the end of 2019. Looking back, it's been a great year for the podcast and
- 1:10all the other stuff we're doing, like our courses, and it's been really humbling to get messages from
- 1:15all of you about how the podcast is helping you in some way or the benefits you're getting from it.
- 1:21And I just want to say thank you for listening because it's a true honor to be able to create
- 1:25this podcast for you. It's a lot of work, but it's entirely worth it. It's really, really great,
- 1:31and it couldn't be done without you listening and sharing it. So thank you, thank you, thank you.
- 1:36Hope your 2019 was great as well. Now let's chat with Dan.
- 1:41Dan, welcome back to Talk Python To Me.
- 1:43Hey, it's great to be back, man.
- 1:44It's great to have you back. It's been a while since you've been on Talk Python, but
- 1:47not too long ago since you were on Python Bytes. That was fun.
- 1:50Yeah, that's right. We practically just finished recording that. And yeah, it was great with
- 1:55Cecil Phillips and yeah, I had some good links that week, I think.
- 1:58Yeah, absolutely. So I'm pretty excited about 2019. It was a good year. How was it for you?
- 2:03It was a very, very busy year, I would say.
- 2:07Yeah, I feel like for you guys, like RealPython has come along a long ways. You've got a lot of
- 2:13authors, you've kind of got this process going, you've got your editorial, your editing, and
- 2:17overseeing how the content creation is going. And you're making a big difference, I think.
- 2:22Thanks. That's good to hear. And yeah, it's just been this incredible year. We're at 75 authors and
- 2:29video instructors published on the site now. So I want to get to 100 next year. That would be a nice,
- 2:34cool achievement, I think. And we also just recently hit 2 million visitors, like unique visitors or
- 2:41readers in a single month, which is kind of this incredible... Let me... I can almost... It totally
- 2:47sounds like I'm super bragging here, but I literally can't wrap my brain around that. It's just kind of
- 2:53nuts and really cool just to see that growth and how it's resonating and how we're getting really,
- 2:59really positive feedback. Yeah.
- 3:00Yeah. I think that's really positive and congratulations.
- 3:02Thank you.
- 3:03Yeah. And I think it speaks one to all the work that you're doing that you talked about. It also speaks
- 3:08to just Python's growth in general, right? Like you're riding two curves and they're both going
- 3:14in the right direction.
- 3:15Yeah, that's true. So how was your 2019?
- 3:17My 2019 was amazing. Didn't skip a single episode on any of the podcasts. And I think that's a pretty big
- 3:24accomplishment actually.
- 3:25That's huge. Yeah.
- 3:26Yeah. And released a bunch of classes. I feel like we've covered some important stories
- 3:31on the podcast, right? That's one of the things I try to do. We can cover every web framework
- 3:36and the person who creates it and that's great and so on. But I really want to highlight that
- 3:40Python is not just for web developers or like straight down the middle of the road data scientists.
- 3:46Yeah.
- 3:46We've had medieval Islamic philosophers and we've had people doing machine learning for particle
- 3:54collisions and all sorts of stuff that might have been back in 2018. But those kinds of stories are really
- 4:00interesting. I think we had a decent amount of those and I'm really happy to be able to share
- 4:05those edge stories that I think are so interesting.
- 4:07Yeah. Yeah. I think that's super cool. And then I think a podcast is just such a great format for it as well,
- 4:12where somebody can come on the show and join you there and really give the listener a chance to
- 4:18understand why this is cool and what the motivation. That's always the most interesting thing for me
- 4:23when I listen to your show, figuring out like, okay, why is your guest doing that? Why are they so into
- 4:27researching Islamic philosophy with Python, which are two topics that I would have never imagined
- 4:33you would combine in some way. And then I listened to the show and I'm like, oh man, it's so cool how
- 4:37broad this is, what people are doing with Python.
- 4:39Yeah. You listen to the story and it makes perfect sense. You're like, of course you should be doing
- 4:43that. And the thing I like about those types of stories is there's a lot of people that think,
- 4:48oh, I'm not a programmer or it doesn't make sense for me to do that or whatever. Like,
- 4:52I'm just a stock trader. I'm just a biologist. And then you hear that and you're like, all right,
- 4:57if somebody can use it for philosophy, thousand year old scrolls, I should be able to find a way to
- 5:02make use of this in my much more mainstream type of job. Right. It's like, yeah, obviously there's all
- 5:08these amazing things people can do. They just got to be a little creative to do it.
- 5:10Yeah. Yeah, absolutely. I feel like we talked about this before, but this whole idea of the dark
- 5:14matter developer, someone who doesn't actually really identify as a developer or programmer,
- 5:19but there's so many people out there who are practically programmers or they're working with
- 5:25code, they're writing code, but they don't really see it that way.
- 5:29A big enough part of the community to actually come along and come to the conferences or blog about
- 5:34programming. They're probably blogging about something else that they care about. Something
- 5:37like that, right?
- 5:38Yeah. Yeah.
- 5:38Yeah. Sweet.
- 5:39Cool. Well, let's talk about what we're going to focus on for this show. So the idea is we're going
- 5:43to take 10 of your popular bookicles, book articles, your articles-
- 5:49That should be a new one.
- 5:50Yeah.
- 5:50So we're going to take our near book style on real Python and just pick 10 of them. We're going to
- 5:56call it the top 10, but it's not necessarily top 10 by your traffic. It's kind of the ones you wanted
- 6:02to highlight from the year, right?
- 6:03Yeah. So yeah, I really wanted to give a chance to sample a wider variety of topics because if you go
- 6:11purely by traffic numbers, things are just going to get overshadowed by popular terms that people
- 6:16search for on Google.
- 6:16Look, it's for Django articles or whatever, right? And just because people are searching for that or
- 6:19whatever.
- 6:20Yeah. And so, yeah. So we kind of assembled a list of 10 articles that we wanted to highlight and then
- 6:26go over and then share with you.
- 6:27All right. Where are we starting?
- 6:28Sweet. So we're starting with an article that's called How to Run Your Python Scripts by
- 6:34Leo Danis Pozo Ramos. And it kind of sounds simple, right? You just go-
- 6:41Right. Don't you just say python space script.py?
- 6:45Yeah. I mean, that's what we do most of the time, right?
- 6:47Some of the time, yeah.
- 6:48Hit control R or something like that. F5. And this article is cool because it, of course,
- 6:56talks about that. But then it goes really, really deep into the behind the scenes and
- 7:02what some of the other ways are that you can possibly use to run Python code. So you could
- 7:07just load the string from Office Script and then just eval it. Or there's the import lib module
- 7:14in Python 3 that you could use. And there's all kinds of other more complex methods where you get
- 7:21deeper and deeper into CPython.
- 7:22You could do python space dash C and like some code, right?
- 7:27You could also do that if you wanted to run a code snippet from the command line. And I just love this
- 7:32article because it starts with the really simple and straightforward and like main use case. And then
- 7:36it goes deeper and deeper and deeper into all the different alternatives. And you know, what the
- 7:41difference is between running a module with Python dash M versus actually just running it by Python
- 7:48space from the command, Python space and then the file of the file name and running it from the
- 7:53command line. And yeah, for that reason, you know, I wanted to highlight that article.
- 7:57Okay. Yeah, that's really cool. And one of the things I like about a couple of the articles that
- 8:01we're covering are I look at the title and I go, yeah, I know that. And then I look at the article
- 8:07and it's like, I don't know how many words, but it's like, you know, readability suggests this might
- 8:11be an over an hour to read this article. I'm like, wait, I thought I just, that was simple and I knew it.
- 8:15And you know, when you, whenever I, that kind of makes me think, I'm like, oh, I actually might learn
- 8:20something here. If I just pay attention, like this is going deeper or into a different area than,
- 8:25because if I thought it was that simple and it's this, then it's clearly I'm missing something.
- 8:28Yeah. As the kind of the person running the site and working on the platform there, like I love
- 8:33seeing surprises like that because it's always a team of us that's working on the article. So we
- 8:37have like multiple review stages and we review the outline and then we review the script and there's
- 8:43like a technical review and just seeing these things kind of grow and you'll become a real Python
- 8:49article is, I just really enjoy that process and being a part of it. So yeah, this is like a great
- 8:54example, I think, of that. Yeah. Yeah. Quite cool. So covers a bunch of stuff and probably something,
- 8:59you know, there's definitely a few suggestions in there that I didn't know. All right. What's number
- 9:04two? And number two is called 13 Project Ideas for Intermediate Python Developers by Habib
- 9:11Shopeyou. And this was born out of a lot of questions that we received over email or Twitter and
- 9:19also most recently in our real Python community Slack where people were asking, like, I feel like
- 9:25I kind of know how to use Python, but I don't know what I should build. I've learned the language. I know
- 9:30loops. I know how to do strings. I create a dictionary, get stuff in and out of it. But what can I actually
- 9:35build that like is the next step? Exactly.
- 9:37Yeah. Because that's often very challenging. It's not just challenging on like maybe a lack
- 9:42of creativity. It's challenging in like, oh, you want to be cool to build Instagram? Like, no,
- 9:47it wouldn't be cool to build. It'd be very hard to build. It's like millions of lines of code.
- 9:50You know what would be cool to build? As a timer, like, no, it's boring and it's too short. Like,
- 9:53what is the right size where it's challenging, but I can reasonably expect to do it if I put in some
- 9:59effort? Yeah. And that's a really hard one, right? Like I was back in the day when I learned how to
- 10:03code or first started. I mean, I guess you never really stopped learning how to program.
- 10:07I was in these like game development forums and there was every single week there was like
- 10:12a new person joining and they were like, I want to build this MMORPG or like, I want to build this
- 10:17like massive thing. And so everybody was working on these like massive projects that never really
- 10:21went anywhere. And I think that could be really, really frustrating. And so my answer to that question,
- 10:25you know, what should I build as an intermediate developer was usually like, just pick whatever,
- 10:29you know, just take a command line app that you use and try to emulate, like try to write your own
- 10:34version of it. But the problem is that doesn't really work for some learners, for some students.
- 10:39And so we wanted to give them a list with ideas, you know, here's some things that we think you could
- 10:42probably pull off. You have a fighting chance of actually like building this app, right? And it's
- 10:47not going to be a world of Warcraft, but it's going to be a cool like alarm tool or a little file
- 10:52manager or a little note-taking application. Yeah. Give us a sense of some of the ideas you got there.
- 10:58Yeah. So the ones that I just mentioned.
- 10:59Yeah, exactly. So MP3 player, URL shortener, file rename. Yeah. That's really nice.
- 11:08Contact book, I think is also something interesting where, you know, there's different ways you could
- 11:12store the data could just be like a little, yeah, like an address book where maybe you ask, you know,
- 11:18it could be as simple as just storing a dictionary to a text file, or then you could get progressively
- 11:23more interesting there and have a little database maybe.
- 11:26You could use SQLite and then you could start using SQLAlchemy because, you know, you don't
- 11:30want to be writing inline SQL and then, you know, become little Bobby tables.
- 11:35Yeah, that's right. Well, you know, someone could take you a great free MongoDB course.
- 11:39Yeah, exactly. Yeah. They could do a MongoDB back one.
- 11:42All kinds of options there.
- 11:43Yeah. They could totally like level these up. They could put them online, all kinds of cool
- 11:46stuff. Yeah. So I like it. And you got it broken down to web, GUI and command line. That's pretty
- 11:50good break.
- 11:50Yeah, that's right. Yeah. We try to give like a high level overview and then depending on what
- 11:54you're interested in, you could pick the right project for you.
- 11:57Yeah. Super. All right. What's next?
- 11:59All right. So I think we are at article number three. And what I wanted to highlight there is
- 12:05the article is called Three Ways of Storing and Accessing Lots of Images in Python by Rebecca Stone.
- 12:11And I think this article is cool because, again, it's something that I never really thought about
- 12:16before. You know, I was like, OK, you know, my Django app uses a bunch of static images.
- 12:21There's just a folder in there.
- 12:22Right, right. That's slash static slash IMG or something, right?
- 12:25Yeah. But what if that maybe doesn't work so great anymore? I think you're storing a
- 12:31massive amount of images. You know, you have some, I don't know, some robot, some probe that's going
- 12:36to Mars and you have lots, you have like terabytes of images. And where are you going to store them?
- 12:40How are you going to make this manageable?
- 12:42Right. Are you going to create some kind of like automated IoT doorbell that always snapshots,
- 12:48whatever's close, right?
- 12:49Yeah. And if your house gets broken in a lot, eventually you have too many images and you got
- 12:54to figure out what to do with them.
- 12:55That's right. Why are all these people at my house? You're killing my storage.
- 12:58All right. So what are some of the suggestions?
- 12:59Yeah. So it goes, the article goes into three techniques there. So the first one is, you know,
- 13:05just like store them on disk as .png files or, you know, JPEG or what have you. And then the
- 13:10second option is using a memory mapped database called LMDB. And the third option is using a
- 13:16hierarchical hierarchical data format like HDF5. And the latter two, I'd never really heard about before.
- 13:27But it turns out, of course, that there is a lot of Python tooling available for these things.
- 13:34And so they provide a number of interesting features. So for example, there's a compression
- 13:39that you could use. So to potentially limit your disk usage. And there's just lots of good tooling,
- 13:46if that's a problem that you're facing, that people can use with Python.
- 13:50Yeah, this is interesting. Like I'd never heard of LMDB, but apparently it's lightning memory mapped
- 13:55databases, which sounds fascinating.
- 13:57It sounds, yeah. It's like, I should definitely check that out. Find a use case for that. Cause that
- 14:01sounds cool.
- 14:01Yeah. You got to build that, that magical doorbell robot.
- 14:05Right. Maybe selfies for robots or something. They just do it all day long. All right. Awesome.
- 14:10All right. So what's number four?
- 14:12Number four is called Speed Up Your Python Program with Concurrency by Jim Anderson.
- 14:17Oh, this is one that definitely, definitely resonates with me.
- 14:20It's, yeah, you have a lot of great material on asyncio and working with parallelism and concurrency
- 14:27with Python. And the idea for this article was to give the reader an overview of what different
- 14:36types of concurrency that are out there. And what does it mean if a program is CPU bound versus IO bound
- 14:41and which options make sense using, you know, when should you use threading versus a multi-processing
- 14:47or asyncio. And we also added an interactive quiz to it. So that, you know, if you're reading this,
- 14:54you can really make sure, okay, I actually understood these concepts because they're pretty
- 14:57difficult to take in the first time.
- 14:59Yeah. That's the kind of thing that just needs to wash over you several times until you're like,
- 15:03all right, I'm starting, I'm starting to get the feel of this thing.
- 15:05Yeah. Get burned by it a couple of times and you're like, oh no, I got to re-architect this again.
- 15:09Exactly. And I think this is important in Python because I think Python's concurrency story
- 15:14is both amazing, but non-obvious in some ways. And what I mean by that is a lot of programming
- 15:21languages, you can leverage computational concurrency by using just threads, right? Because I got, you
- 15:27know, this thing believes it has 12 threads in my MacBook here. It has six hyper-threaded cores,
- 15:32right? So if I were to like write a single-threaded program, it'll get like eight or 9% CPU usage
- 15:37and that's it. So if I want to make that go faster on a lot of languages, C++, C#, whatever,
- 15:41I can just create a bunch of threads and it can start running on all of those different threads.
- 15:45But in Python, we have the gill, so it doesn't work, right? And that's, I think, actually caused a lot
- 15:50of challenges because people say, well, that means Python's concurrency is broken. It's not broken.
- 15:55It just needs a clearer mental model of when to apply each technique.
- 15:59Yeah. It's kind of like a manual gear shift, right?
- 16:01Yeah. Yeah.
- 16:02It's not broken, but the car is also not going to go.
- 16:04It drives in the day, but it won't drive at night. Put it in night mode. It won't go.
- 16:09Put it in N.
- 16:11Yeah, exactly. So for example, if it's IO bound, probably what you want to do is something
- 16:17to do with asyncio, right? But if it's computational, you really need to do, at least for the moment,
- 16:22something with multiprocessing.
- 16:24Yeah.
- 16:24And so it compares those types of things, huh?
- 16:26Yeah, exactly. And like I said, you know, we have this quiz at the end that you can take
- 16:30and then really make sure, okay, I understand what the differences are between these concurrency
- 16:35models.
- 16:35This portion of Talk Python To Me is brought to you by Linode. Whether you're working on a personal
- 16:41project or managing your enterprise's infrastructure, Linode has the pricing, support, and scale that you
- 16:47need to take your project to the next level. With 11 data centers worldwide, including their newest
- 16:52data center in Sydney, Australia, enterprise-grade hardware, S3-compatible storage, and the next-generation
- 16:59network, Linode delivers the performance that you expect at a price that you don't.
- 17:03Get started on Linode today with a $20 credit and you get access to native SSD storage, a 40-gigabit
- 17:10network, industry-leading processors, their revamped cloud manager at cloud.linode.com,
- 17:15root access to your server, along with their newest API and a Python CLI. Just visit talkpython.fm
- 17:22slash Linode when creating a new Linode account and you'll automatically get $20 credit for your
- 17:27next project. Oh, and one last thing. They're hiring. Go to linode.com slash careers to find
- 17:32out more. Let them know that we sent you.
- 17:34Number five.
- 17:37All right. Number five. Build a recommendation engine with collaborative filtering by Abinaf
- 17:43Aitzeria. And what do you think this is?
- 17:47I'm reading a real Python article and it says, you might also like these other three or something
- 17:53like that or talk Python course. You might also like this one, right? It's a good follow-on
- 17:57for various reasons, right? People who took this course usually took that one next or people who
- 18:01read this article also like shared that other article or something.
- 18:05Yeah, exactly. It's about building a recommender or recommendation engines like you would have on,
- 18:10you know, pretty much any larger website like Netflix or Amazon. They're all recommending you
- 18:16products or movies that you might enjoy based on what you already watched. And a lot of times what
- 18:22they do is they look at, kind of build a profile of the things that you watched and then kind of
- 18:28finding similar users, other users on the platform that watched those movies and enjoyed them. And
- 18:33then based on that, trying to figure out, okay, what did these other people also watch and enjoy?
- 18:37And maybe we can recommend that back to you and then hopefully you'll have a good time on the
- 18:40platform.
- 18:41Yeah, that sounds really cool. It sounds like very relevant to data scientists and there's probably
- 18:45a lot of data science algorithms in there, huh?
- 18:47Yeah, absolutely. I think there's some cool stuff happening there and there's some matrix math.
- 18:51What I like about this article that I really like how it turned out from like a typesetting
- 18:56perspective. So that was like a really big aspect of kind of building the new real Python
- 19:01CMS and hosting platform and built on Python 3, Django 2 and all the good things. It was a lot of fun
- 19:07building it and working on it. And I mean, I'm still working on it. And I think this is just a cool
- 19:12showcase for that also, you know, where you get some graphs in there, you get some interactive,
- 19:16or you get some code snippets that you can copy and paste and you get some math typesetting there.
- 19:21And I think that makes it very engaging to the reader as well. And yeah, and it's just a cool
- 19:28topic. Like I'm just fascinated by those things, you know, how you can use the wisdom of crowds or
- 19:33whatever that way. You know, you could say like, well, we have enough people using the platform,
- 19:36you have enough people watching Netflix. And then all of a sudden I can get these amazing
- 19:40recommendations for other things I would have never thought about watching.
- 19:42Yeah. You help it make it better for other people without even knowing it, right?
- 19:45Yeah.
- 19:45Your actions are there and used for good. Yeah. So it talks about things like K nearest neighbors
- 19:50and probably the fundamental algorithm there that's being used, right?
- 19:55Yeah. I believe it's for this particular recommendation system technique called collaborative
- 20:00filtering. But there's also other approaches that I can't really speak intelligently about.
- 20:06Yeah, sure. There's even some cool recommendations like the surprise recommender system, which is a
- 20:11Python scikit-learn extension, right? So you can install scikit-surprise.
- 20:17It's a cool name for recommender system.
- 20:19That's a great recommender, right? Like surprise, we actually can recommend something useful. This is
- 20:23not like wasted space here. Yeah.
- 20:26Cool. Yeah. So if people are interested, they can check that out. And also I noticed it's kind of
- 20:31got 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:35Anaconda, here's how you use that as well, right? So this one seems like there'd be a lot of folks
- 20:40using Anaconda as their Python distribution to work on this.
- 20:44Yeah. I think if in the data science space, Conda seems to be quite popular. And so typically we kind
- 20:50of standardize like for the articles, we standardize on just using pip because that's kind of the lowest
- 20:54common denominator. Yeah.
- 20:55But in this case, you know, we felt like it makes sense to be closer to where the target audience might
- 21:02be there. Right, right. Take it to the data scientists, right?
- 21:04Yeah.
- 21:06That's really cool. So I love it. It's a good one.
- 21:08Number six on our list here.
- 21:11Right. So this one might be a bit surprising, but it is called Your Guide to the Python Print
- 21:16Function.
- 21:16And this is the one that I was talking about when I thought like, okay, I'd know this thing.
- 21:20Yeah.
- 21:21Like, wait a minute, maybe I don't know this thing.
- 21:23So this is more like a book about the Python print function by Bartosz Zaszinski. And this is just this
- 21:33incredible deep dive into the print function slash print statement in Python 2. Because again, you know,
- 21:39would think, okay, maybe this is maybe a paragraph or two about what you can do with the print function.
- 21:43You know, you can pass some arguments to it.
- 21:45It requires parentheses now. It didn't used to.
- 21:47Exactly. Right. Like what else is there to say? And then it goes really, really deep into the
- 21:52history of the print function and some common use cases that maybe you might not associate with the
- 21:58print function directly upon first glance. You know, for example, well, how can you build a cool
- 22:03console user interface? How can you do colors in the terminal? And how can you pretty print if you
- 22:10have a nested data structure, like some JSON that you parsed into dictionary? How can you make sure
- 22:14it actually looks good when you print it out to the console or some debug window? And so it's not
- 22:20just purely about the print function, but all the kinds of different best practices and ways you can
- 22:25make printing better in your Python programs.
- 22:28Yeah, that's cool. No one wants to try to use a minified dictionary for debugging.
- 22:33Nope. That's very annoying. I usually take those and then paste them into the black online
- 22:39format. I get like a nicer representation. Yeah. Yeah. Yeah. So we cover some of the things I
- 22:45think are actually not super obvious to new folks coming from the language, right? Like
- 22:50that's right. If you come from other languages, you might not know that you can actually use a
- 22:55keyword argument to set the end to be instead of a backslash end to be like a comma and print on one
- 23:01line with a bunch of commas or something like that or the buffering, right? If I'm trying to do
- 23:06something computational and print out as the computation is happening, a lot of times that
- 23:11can get buffered up and then it like all shoots out at once. Or, you know, like if you're like
- 23:15delaying waiting on something, you want to actually see all the output. Like there's a bunch of little
- 23:19tips like that in there, right? Yeah. Yeah. And like with everything, it's there's a deep rabbit hole.
- 23:24Yeah. Down the rabbit hole you go, right? Yeah. I love this kind of article where you think, okay,
- 23:30we're going to scratch the surface here a little bit and then we're done. And then there's all kinds
- 23:34of interesting other things you could do or just learn why certain things work the way they do. You
- 23:40know, ANSI or ANSI escape sequences for making the making colors in the terminal. When you read about
- 23:48them, they kind of looks like this incredibly confusing format. And then you learn a bit more
- 23:52about the history and you know how it relates to the sort of these old school terminals of the old
- 23:57like mainframe computers and how, you know, it's just a format that has grown over decades. And
- 24:03well, sure, we could all, you know, throw it away and maybe engineer something from scratch. But it's kind
- 24:07of cool to understand, you know, if I'm, if I don't know, you know, boot up my Windows computer or
- 24:12MacBook in, in 2020, why it's still supporting that stuff and how it goes back, you know, 50 years.
- 24:18Yeah. Well, another thing that I think makes a night and day difference for these simple little
- 24:23command line apps is color. More of those should use color, right? If you're saying in the help output,
- 24:29it would be great to show the required arguments is like one color and the optional ones is another.
- 24:34And 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:40cross platform or whatever, then you won't.
- 24:42Yeah. Yeah. Oh, speaking of color there in the terminal, one of my favorite tools is the B Python
- 24:47REPL.
- 24:48B Python?
- 24:49B Python. So the letter B, and then Python, one word. It's a Python interpreter, like a Python, not an
- 24:56interpreter, but a REPL environment. That is just like the when you start Python from a command line,
- 25:01you get your little prompt and you can type a Python code into it and run it. But it does
- 25:05syntax highlighting. So it'll give you beautiful colors in the terminal.
- 25:09Nice.
- 25:09And it also does autocomplete, which is kind of cool.
- 25:12So we use that all the time in our video courses and examples. And people always ask like,
- 25:18oh, what's that? What's that tool? I want to use that too. And it's great. Like,
- 25:21like the color really adds a lot of value.
- 25:23It 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:27PT Python. Are you familiar with that?
- 25:29Oh, that's great too. Yep.
- 25:29Yeah. It's like Emacs in the REPL kind of. Yeah. It takes me back to my Emacs days. So last thing,
- 25:36like we go on and on about this, like incredibly for a really long time about printing. But there's
- 25:41one thing that's in here. I think that's, that's pretty interesting that they talk about that I guess
- 25:45also surprised me. I didn't really think about it is mocking the print function for unit tests.
- 25:50Yeah. That's a kind of a surprise, right? But it's, it's actually a pretty annoying problem. If you,
- 25:56if you want to write tests for a program where in the test, you actually want to make sure it's
- 26:00printing the right stuff. Well, how do you do it? You know, how can you actually redirect that output
- 26:04into some kind of buffer so you can inspect it and say, okay, we got the output that we wanted.
- 26:09I called this and it said, enter this or whatever, right? Like the prompt that we were expecting or
- 26:14something. Yeah. Yeah. Yeah. Yeah. Pretty cool. All right. Well, let's move on because it is the
- 26:20print function, but it is actually really, really interesting. And what are we up to number?
- 26:24I am trying to check. I think number seven, this is number seven. Yes. Number seven. Yeah. And it
- 26:30goes right along to number eight in a sense. So how to write beautiful Python code with PEP 8.
- 26:36Yeah. So this is a cool article by Jasmine Feiner and it's about the PEP 8 style guide and sort of
- 26:44a beginner friendly intro to PEP 8, why it exists, how it can help you format your code in a way that
- 26:51other Python developers will expect and appreciate. And I think it's, it's a really good one because,
- 26:58you know, it breaks it. Like if, when you read the actual PEP 8 can be feedback that I heard in the
- 27:04past, it's just very, very overwhelming to take it all in and take all the examples in. So we try to
- 27:08break it down and give you a good overview and then point you to the original PEP so you can do the deep
- 27:15dive. Yeah. It's really cool. And you know, it's one of those things that's really important that,
- 27:20so you look like you belong, right? If you start doing stuff that is, you know, Java style or C#
- 27:28style and someone says, yeah, I'm interviewing for a Python job. And here, let me write a little
- 27:34code for you and you start using like camel case method names or something like that. You're like,
- 27:40not so sure you're a Python developer. You don't look like you're from around here, right?
- 27:45Yeah. First impressions matter, I guess.
- 27:48Yeah. And you know, once you know the conventions, some of those conventions have meaning,
- 27:52right? Like the underscore has a certain meaning and things like that. And so it's not implicitly
- 27:59obvious from that thing that what the meaning is. But once you study it, then you get to know,
- 28:04right?
- 28:04Yeah. Yeah. I'm actually, I wanted to ask you what's, is your talk Python, is the code for the
- 28:09talk Python platform? Is it PEP 8 compliant?
- 28:11Is it PEP 8 compliant?
- 28:12It's both for the platform it is, I would say PEP 8 compliant. And I try to do that in the courses.
- 28:18Probably the way I do that most is just running, like working on everything in PyCharm and PyCharm
- 28:24will highlight stuff and make it obviously, it'll like, as you type a highlight, it'll go, no,
- 28:29no, no, no. There's something clearly wrong. Like you don't have an underscore, you have camel case
- 28:33on a variable name. Stop doing that. Right. And so, yeah, I don't run anything like black across
- 28:38the whole thing. The only thing I've run entirely across the whole code base, not across the courses
- 28:44because it's recorded. So it'd be weird to change it. But in terms of the platform, I've used Flint.
- 28:49Are you familiar with Flint?
- 28:50I feel like I heard about it. Is this another auto format?
- 28:54It has, it's a very special tool, but I love it. What it does is it will take all the various string
- 29:00formatting styles of working with strings. So percent, value value, or the format, something
- 29:08or other, and so on. And it turns on all the f-strings.
- 29:10Oh, that's cool.
- 29:11Yeah. It'll just rewrite your code, like rewrite all your f-strings.
- 29:14I know a certain core Python developer who would love that. Marietta.
- 29:17She does all these awesome stickers.
- 29:20Yeah, yeah. Yes, man. Yeah. So I ran it. In the early days, it had a couple of bugs when you were doing
- 29:26numerical formatting, like this number, comma, colon, comma, like 0.2F. Like that would get freaked out.
- 29:34But yeah, like after a couple of iterations, it's really quite good.
- 29:37Oh, that's cool. I think, yeah, I got to run that. That's great.
- 29:40Yeah. So I just ran it against like 20,000 lines of code across the training site and the Talk Python
- 29:44and Python Bytes websites. And I think there was like maybe one mistake. So I just,
- 29:49I looked at the diff before I checked them all in and just said, actually this, you know,
- 29:52one out of a thousand, there's this mistake. But yeah, yeah.
- 29:55I think actually those are probably pretty much gone. But yeah, anyway,
- 29:57and it's not PEP 8, but it's a sort of a continuation.
- 30:00Yeah. And I think with this stuff, I feel like we've got to be clear, like it can often be ambiguous,
- 30:05right? Like any, any sort of code style guide, like PEP 8 or what have you, you know,
- 30:09in other languages, it's usually not at the end of the day, like naming is a big part of a
- 30:15developer's job, I think, you know, and in picking names that are
- 30:18actually communicating the intent well and other people can understand.
- 30:21And so it's, it's, it's not going to solve that problem because, well, even though if,
- 30:26you know, if you're following PEP 8 to a T and you're using all the upper and lowercase letters
- 30:30in the, in the right way, and your naming isn't, just doesn't make sense, then that's also not
- 30:35going to be great. So it's, yeah, another example might be struggle.
- 30:38Yeah. You're doing a list comprehension and it's all on one line, right? It's got the,
- 30:43you know, and for N and such and such, if N such and such. And it happens to be 79 line characters
- 30:49long. So it's on column 79. It's fine. You don't need to wrap it, but it's like super hard to
- 30:54understand. It would make sense to have that three lines, the select value, the loop, the,
- 31:00the collection is going through and the test, right? It would be much better. But PEP 8 doesn't say,
- 31:04well, if it's 79 lines and complicated, it should be broken up. But 80 lines is, you know,
- 31:10like the hard limit and things like that, right? Yeah. Yeah. And so we've got to think beyond it.
- 31:13Are you following the 79 characters limit in your code basis?
- 31:17Do I follow? Sometimes. There's a few times where I don't like, so if I have a, a raw string or
- 31:24multi-line, not raw string, a multi-line string where you do triple quote, then like there's a bunch of
- 31:28stuff 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:33be in the string is more than, or 80 columns, but he would still complain to me like, oh no,
- 31:37this line is 120. I'm like, yeah, but you show me how to fix it and we'll have a conversation,
- 31:41but I can't fix this, right? Yeah. Without completely going, you know what, we're going to have a string
- 31:45concatenation like to nobody's end rather than this multi-line string. So there's a few edge cases,
- 31:51but I try to. Yeah, me too. Like ever since I started using black, you're like, black's going to change
- 31:55it anyway. I think you can tell it like to use a different line length limit. Like I feel like that's,
- 32:00that's always something that comes up where it's like a kind of controversial topic where should
- 32:05you follow the 79 character limit is even another, there's like a 72 character limit recommendation
- 32:10for doc strings. Like I try to follow that as well. I have like my, you know, these like a little,
- 32:15little gutter margin set up in the editor. So yeah, exactly. That's cool. But then at the,
- 32:19sometimes I'm thinking, okay, but wouldn't it be nice just to go a hundred characters or longer?
- 32:22So I think, I think like whatever number of people pick, as long as you're consistent,
- 32:25it's, it's probably a good thing. Yeah. It's somewhat contextual.
- 32:28This portion of Talk Python To Me is brought to you by Brilliant.org. Let me knock something off
- 32:35your holiday to-do list. Gifts. Spread the love to your loved ones by gifting them Brilliant.
- 32:41This really excites me because it's such a fun way to nurture curiosity, build confidence,
- 32:46and develop problem-solving skills crucial to school, job interviews, or to their career.
- 32:50Brilliant's thought-provoking content breaks up the complexities into bite-sized,
- 32:55understandable chunks that will lead them from curiosity to mastery. Go to talkpython.fm
- 33:01slash brilliant and grab a gift subscription to help your loved ones finish their day a little
- 33:06smarter this season. That's talkpython.fm/brilliant, or just click the link in the show notes.
- 33:13We talked about Pep 8. Now how about Article 8? Article 8 is about the Python Lambda function. So it's called
- 33:21How to Use Python Lambda Functions by Andre Bourgo. And yeah, I wanted to highlight this one because
- 33:28Lambdas and Python are a topic that can be challenging. I think it's something that a lot of times you don't
- 33:37really have to, you don't really work with. And so you don't get a lot of experience working with it.
- 33:41And then when there might be a situation where it's actually useful, for example, if you want to
- 33:45sort a list or something sorted by a custom key, then if you don't know about Lambdas,
- 33:50it's going to be a frustrating experience.
- 33:52Right, right. Like I got to write this other function and that's kind of weird. But yeah,
- 33:56so they're one of the things that when you learn them, you're like, man, that is cool. I can't
- 34:01believe I can think of immediately 10 places I would use this, but they're not obvious that they exist
- 34:06or that you could use them until you see them, right?
- 34:07Yeah, that's right. And it's, what's the quote there? Like the dose makes the poison or what?
- 34:12I only know the German version.
- 34:14Yeah.
- 34:15Die Dose macht das Gift.
- 34:17Yeah.
- 34:18So the dose makes the poison.
- 34:19Yeah. Basically you don't want to, you want to apply it. It's like salt, you know, you don't
- 34:24want to overdo it with the salt because then the food's going to taste it.
- 34:27Yeah. Yeah. A pinch will do you. Absolutely. So yeah, that sounds about right.
- 34:31Yeah. And so, so this article goes into some use cases and also into the kind of the language
- 34:37history or why are these types of functions called lambda functions and how does this relate to this
- 34:44thing called lambda calculus that was invented in the 1930s. And we go back into some of the computer
- 34:50science stuff.
- 34:51Yeah, that's cool.
- 34:52So you can also learn about that.
- 34:53You know, another thing that I think is interesting that gets very little attention,
- 34:57I suspect this is happening to a non-trivial number of people and they don't even know is closure.
- 35:03Right? So closure is the idea that like I have a variable that's either available in the local
- 35:08method or it's a global variable. Most likely it's like a local variable on that method.
- 35:14We're using the lambda and you say it in the function body, the lambda body, but not as an argument.
- 35:22Right. It's somehow magically.
- 35:23Kind of capturing that.
- 35:25Yes.
- 35:25I find this so hard to explain just in audio only because when you see it with an example,
- 35:30like in the article, it's to me at least a lot easier to wrap my head around it.
- 35:35But yeah, let's give it a shot.
- 35:37Like can we.
- 35:37Yeah. Well, some really interesting stuff happens with closure, right?
- 35:41It's not just that the variable is like passed, but it's remembered.
- 35:46It's remembered across function calls.
- 35:49So even if you change it and then you call the lambda again, it will work with not the
- 35:53original value like a compi, but it'll work with a changed value.
- 35:56Which can really bite you also if you're referring to a mutable object and you think you've kind
- 36:02of captured the full state of this object and then it gets changed under you.
- 36:08which I think this is also kind of maybe the danger of using lambda is that if you don't
- 36:13understand how closures work or when that effect kicks in, that you might be writing code that
- 36:21actually breaks under unexpected circumstances.
- 36:24Yeah.
- 36:25And it can be incredibly hard to understand why if you have no idea that this is happening.
- 36:29On the flip side, you can use it for great power as well.
- 36:33Like let's just go to like something super simple.
- 36:35I want to sort a list.
- 36:36I want to say key equals lambda of item, colon, do something with the item, right?
- 36:43But maybe there's other variables or other data that's in the function that you want to use to
- 36:50decide how you sort.
- 36:51Like if it's below this cutoff, I want it first.
- 36:54But if it's after this cutoff or like, you know, it's somehow you've got to compute with some other
- 36:59data that's not purely just the item.
- 37:01Like if you wanted to sort, you had an address book with, I don't know, name and year of birth
- 37:06and you wanted to sort it by some calculated value.
- 37:10Yeah.
- 37:10So like both of them.
- 37:11Right, right.
- 37:12So if they don't have a date of birth, you could have like, here's the default date of
- 37:15birth we're going to use.
- 37:15Right, yeah.
- 37:16Right, right.
- 37:16Substitute something.
- 37:17Yeah, they're all going to be born in 1970 or something.
- 37:19Who knows?
- 37:19So you could like have that as a local variable, but then include that in your sort lambda.
- 37:24But the function that's getting called, it only takes the item and the list doesn't know
- 37:30about your need of this other variable.
- 37:32It's not going to pass it in, but you can just use closure to just capture it and just like
- 37:36bring in more arguments into your lambda than would otherwise be available.
- 37:40And that's a super powerful thing you can do.
- 37:42Yeah.
- 37:42Yeah.
- 37:42I think that probably the main use case, what I personally use them for, there's also
- 37:47a section in the article that talks about whether lambdas are, we can consider them pythonic
- 37:53or not.
- 37:54Because in PEP 8, which we just talked about, there's actually a recommendation there that
- 37:59says you should always use a def statement.
- 38:02So define a proper function instead of an assignment statement that binds a lambda expression directly
- 38:07to an identifier.
- 38:07And so this is like a strong discouragement to using lambdas.
- 38:11I think mainly when you actually, you want a named function.
- 38:15I think anytime you actually want a named function, you should probably not use a lambda.
- 38:18But if it's like a one-off thing, that's where I would use it.
- 38:22Yeah.
- 38:22You even talk about in your article a little bit, like anonymous functions, meaning they
- 38:26have no name.
- 38:28You're passing them somewhere.
- 38:29You're modifying the behavior like of the sort or whatever, but you're not naming the
- 38:34thing doing that.
- 38:35Yeah.
- 38:35That's right.
- 38:36And with great power comes great responsibility.
- 38:40That's right.
- 38:41I think one of the key essence of the lambda, like decide, should I make a separate function
- 38:47or should I make a lambda function?
- 38:49I think one of the key differences here, or the key decision, at least for me, is, is it
- 38:54going to be clearer to just plunk the implementation right here than to give it a good name and put
- 39:01it somewhere else?
- 39:01So if it made a lot of sense to give it a good name and put it over there, because it's kind
- 39:05of complicated, but the name tells you what it does and then use that as the sort, great,
- 39:10do that.
- 39:10But if it's like, I'm going to sort just by like sort of list of customers, it's just
- 39:15lambda of C colon goes to C dot name.
- 39:17Okay.
- 39:18Like it would be more confusing to move that away because then you have to be sure like
- 39:22sort by name.
- 39:23You're like, oh, wait a minute.
- 39:24Descending or ascending?
- 39:25Well, it used to, they renamed it to say sort by name ascending, but then they actually changed
- 39:29implementation to descending, but they forgot to rename it because they're afraid to break
- 39:34the code.
- 39:34And just like, there's all sorts of weird stuff if you move it away.
- 39:38So if it's clearer to have it like in line than lambda, otherwise not lambda.
- 39:43That's my test.
- 39:45That's a good rule of thumb.
- 39:46I feel like I mainly use lambdas for exactly that, that use case and otherwise try to stay
- 39:51away from them.
- 39:52If you have to line break a lambda, that's a problem.
- 39:54Yeah.
- 39:54Yeah.
- 39:54That's, yeah.
- 39:55That's maybe also a good heuristic, right?
- 39:57Where, yeah.
- 39:57Yeah.
- 39:58You could only have, you know, basically you can just put an expression into it.
- 40:01So that's the other thing that we haven't even talked about.
- 40:03So they're also limited in what you can actually put into a lambda function.
- 40:06Right.
- 40:07So you can pretty much just have a single expression that would also be the result of which will
- 40:12also be returned as the return value of that, of that function.
- 40:16And that also limits you, but of course you could use all kinds of ugly work to do something
- 40:23that you're not really supposed to do with them.
- 40:26Exactly.
- 40:26Exactly.
- 40:27But you can't have multi-line lambdas in Python, whereas you can in other languages.
- 40:31Like for example, C# has lambdas.
- 40:33They're basically the same idea, closure and all that, but you can put curly braces and make
- 40:37it 20 lines long if you think that's a good idea.
- 40:40That's like a great idea.
- 40:41JavaScript's kind of like that, right?
- 40:43You can like function curly or parenthesis argument and then just curly braces, right?
- 40:48So to tell you a secret, I feel like what forced me to understand closures was doing more JavaScript
- 40:56development because you cannot avoid them.
- 40:57Yeah, closure's all over the place in JavaScript, right?
- 40:59Yeah.
- 40:59Yeah.
- 41:00Yeah, it is for sure.
- 41:01And they have like similar ideas.
- 41:02They don't call it lambda, but like they have anonymous functions basically.
- 41:06Yeah, that's right.
- 41:07Yeah.
- 41:07All right.
- 41:08Are we already at number nine?
- 41:09Number nine.
- 41:10Number nine.
- 41:10There we go.
- 41:11Yeah.
- 41:12So number nine is about Python coding interviews.
- 41:15So the article is called How to Stand Out in a Python Coding Interview by James Timmons.
- 41:19And I felt that this is an important topic and it's hopefully also something useful for you,
- 41:27dear listener.
- 41:28Maybe you have a Python coding interview coming up or you're worried about, you know, when
- 41:32the day comes where somebody is going to grill you on your Python skills.
- 41:35And we put this article together to cover some common situations there, basically some tips
- 41:41that you can use to showcase your deep understanding of the Python programming language.
- 41:47Yeah, you've broken into a couple of sections, right?
- 41:51You've got like know your built-in functions, know the right data structure, take advantage
- 41:56of the standard library, right?
- 41:57If somebody says, I want you to use the quick sort, you're like, you know what?
- 42:01I created a list.
- 42:02Tim sort.
- 42:02Yeah, yeah, exactly.
- 42:04Or something like that, right?
- 42:05Or I think the data structures is super important.
- 42:08That's a great giveaway.
- 42:09Like I want you to get a bunch of, I don't know, say users and I want you in memory and
- 42:14I want you to look them up by ID and I want you to do that quickly, right?
- 42:18Like dictionary.
- 42:18Yeah, dictionary.
- 42:19Does look up quickly happen?
- 42:20Is that the question?
- 42:21Dictionary.
- 42:22Just yell dictionary.
- 42:25Dictionary.
- 42:26Exactly.
- 42:27Or unique or distinct.
- 42:29Okay, set, right?
- 42:30Yeah.
- 42:31Did they say distinct?
- 42:31They mean set, right?
- 42:33Like just right away, there's, you could have like a complicated 10 line for loop where
- 42:38you test, have you seen it before?
- 42:39Or set, right?
- 42:41Like that's both knowing the built-ins and knowing the right data structures, I think.
- 42:44Yeah.
- 42:44And it is so much good stuff in the Python standard library or in the core language, you
- 42:48know, another great one I think that's worth knowing about is in the collections module,
- 42:52the counter class.
- 42:53Oh yeah.
- 42:54It's if you ever need to count different items or, you know, how often does this string
- 42:59or this word occur?
- 43:00Right.
- 43:01I got a list of text.
- 43:02Like a whole bunch of domain names.
- 43:04I need to know like how many, each one of them appears.
- 43:07Right.
- 43:07That sounds like a challenge or it sounds like two lines.
- 43:09If you know counter, right?
- 43:12Yeah.
- 43:13You create a, you import collections, you create a counter, they're most common.
- 43:16Right.
- 43:17But like these things are incredibly simple when you know them, but if you don't know they
- 43:22exist, it's really challenging.
- 43:24And I think that's actually a problem from, not a problem, but a, a learning challenge
- 43:28kind of going back to your other article.
- 43:31I don't remember which number it was, but the one, I think maybe number two about all
- 43:35the projects, right?
- 43:37Like some of those projects would be really easy if you knew the right libraries.
- 43:41But if you thought I have to write this from pure Python from scratch and I've got to implement
- 43:45this stuff, right?
- 43:46Like, oh, that MP3 player is super hard.
- 43:48Like, let me get down to the bytes and look at it.
- 43:50Like, no, you pip install like the MP3 library or whatever, like it is that works with that,
- 43:56right?
- 43:56It's, there's a whole lot of options.
- 43:58And I think learning Python is challenging because you learn the language and you think
- 44:03you've done it, but you've only like hit the 10%.
- 44:05Now you've got to learn the standard library.
- 44:07Then you've got to learn everything on awesome Python or PyPI or, right?
- 44:11So there's these levels.
- 44:12And, you know, but I do think for tests, for interviewing, knowing the foundational stuff
- 44:17is most important.
- 44:18I agree.
- 44:19Yeah.
- 44:19And we were thinking, you know, we're going to pick stuff that is actually very likely to
- 44:23come up in an interview because in an interview, I think you're not going to get super specific.
- 44:28You know, you're not going to talk about the LMHDB or whatever the lightning memory database
- 44:34that we talked about earlier.
- 44:35That would be, nobody's going to expect, I mean, depending on the kind of role, but if
- 44:40it's, if it's data science, they might expect you to know NumPy.
- 44:43Right.
- 44:43If you've claimed, you know, Python, you better know NumPy at least cursory, right?
- 44:47Yeah.
- 44:47And if you claim that you, you especially better know about things like the collections module,
- 44:52you know, these like core things.
- 44:53Yeah.
- 44:53Yeah.
- 44:54For sure.
- 44:54Yeah.
- 44:55What about when you get stumped?
- 44:56What is your thoughts on like, you know, how do I do this thing?
- 45:00Like, you know, inside your thing, screaming, like I have no idea.
- 45:04Yeah.
- 45:04I start sweating profusely and shivering.
- 45:07Go into the fetal position.
- 45:09That's why I'm running my own company now.
- 45:11Yeah.
- 45:13No, that's a tough one.
- 45:14I think the advice that I would give is start asking questions because it's oftentimes not
- 45:20a good sign if you ask someone a question in an interview setting and they immediately launch
- 45:24into writing code or they feel like they're expected to know the answer off the bat.
- 45:28A lot of times what the interviewer will want to see is how are you approaching a problem?
- 45:33Are you able to get help?
- 45:34Are you able to ask intelligent questions?
- 45:36And even if you don't know the specifics, I mean, nobody really expects that, right?
- 45:40A lot of times if you can use Google, if you can use Stack Overflow, if you can use, you
- 45:43know, Talk Python and RealPython and all these sites that are available to you, you would have
- 45:48that in your normal working environment.
- 45:50You know, like I use Google and Stack Overflow like probably like hundreds of times in a productive
- 45:55day.
- 45:55I use it shamelessly without guilt or judgment, right?
- 46:00I mean, because there's a bunch of stuff that you need to know and then there's a bunch
- 46:03of stuff that just doesn't deserve to take up space in your memory, right?
- 46:08And you should just be able to go, I'm just going to Google it.
- 46:11I don't know what the right way to do this library with that thing is.
- 46:14I'm going to Google it.
- 46:16But just like actually knowing that it exists and I just don't remember quite how to use
- 46:19it, I think is like the big step.
- 46:21Like I know I know there's a counter thing and I know I can get it to group by the count.
- 46:26I just don't remember how to the steps to make that happen, right?
- 46:30Like I think that's okay.
- 46:31Yeah, I think that's totally okay.
- 46:33So just duck, duck, go it.
- 46:35Just bing it.
- 46:36Google it.
- 46:37Just duck, duck, go it.
- 46:39AltaVista it.
- 46:40I don't know what else is there.
- 46:41Yahoo it.
- 46:42Yeah, yeah.
- 46:42AltaVista.
- 46:43That's a good one.
- 46:44I remember that.
- 46:44That was good.
- 46:45One other thing I would sort of put out there is like a huge turnoff to me if I was
- 46:50interviewing, I did that for a while with people.
- 46:52If I feel like they are lying to me, they're done.
- 46:55I don't care if they seem good.
- 46:57If I say like, oh, how would you do that with SQLAlchemy?
- 47:00Oh, like I've used so much SQLAlchemy.
- 47:02And then you can tell like they've never, ever, ever seen it, right?
- 47:06Like they don't even, they can't even describe like, well, what I would do is create a class
- 47:09that derives from like another class and it maps to the database.
- 47:12Like that's a foreign idea.
- 47:14But they're claiming like they've used it in production.
- 47:17Like done.
- 47:18Not a good strategy.
- 47:19Not, I would, I don't know.
- 47:20How do you feel?
- 47:21Like, would you hire that person?
- 47:22Because everything else comes to the question, right?
- 47:24I agree.
- 47:25It's, it's, yeah.
- 47:26It's at that.
- 47:26You want to find, find out, would you ask the interviewer?
- 47:29I feel like you also want to find out, would you want to have this person on your team?
- 47:33Would you want to work with them?
- 47:34Right.
- 47:34Would I trust them to be?
- 47:36Yeah.
- 47:36They start making up stuff like, hey, you know, did you review that pull request or request?
- 47:40Or did you merge that hot fix?
- 47:42Or did you, I don't know, do that?
- 47:43And then you feel like you can't really rely on that person and it's not a good start.
- 47:47Or we're going to build an e-commerce backend.
- 47:50Who's done payment stuff before and feels like they can do it, right?
- 47:53And maybe not.
- 47:54I don't know.
- 47:55Definitely use floats for currency.
- 47:56Yeah.
- 47:58I don't know if we have that one in the list, but that's, that's also a really common question.
- 48:02I feel like where people are like, oh, what data type should you use to represent currency
- 48:06in your program?
- 48:06Right.
- 48:07Right.
- 48:07Integers probably.
- 48:08Yeah.
- 48:09Yeah.
- 48:09And then break it down to sense and then use integers.
- 48:11Yeah.
- 48:12Just round it.
- 48:13Just round it.
- 48:13Just round it.
- 48:13About a dollar.
- 48:15Yeah.
- 48:16It's all good.
- 48:19It's about a dollar.
- 48:20All right.
- 48:21Well, we're coming up on the grand finale here.
- 48:24And this is another one that I could, I'm very passionate about.
- 48:26I could riff on for a long time.
- 48:28So you'll have to stop me at some point, but it has to do with the object oriented programming
- 48:33component of Python.
- 48:35Yeah.
- 48:36So the article is called inheritance and composition, a Python OOP guide by Isaac Rodriguez.
- 48:42And I think inheritance and composition, that is the, one of the core pieces of object oriented
- 48:50programming.
- 48:50And in my experience, it's also the piece that if you're completely new to OOP and you're trying
- 48:56to understand, okay, well, how is this helpful?
- 48:58Like how does this work?
- 48:59It can be a sticking point for some people.
- 49:01Yeah.
- 49:01So we wanted to do a dedicated article that is, yeah, basically a deep dive on inheritance.
- 49:05It sounds a little bit like modeling with objects and just like some practices around
- 49:10that.
- 49:10Right.
- 49:11Yeah.
- 49:11And how do you go about like breaking down a hierarchy or like, I guess a domain into a
- 49:17hierarchy of objects?
- 49:18Yes.
- 49:18Yeah, exactly.
- 49:19That was getting at.
- 49:20And so maybe we should define inheritance and composition.
- 49:23I think inheritance is pretty clear.
- 49:25Composition might be a little less well known.
- 49:27So inheritance is, I want to model like a bunch of cars.
- 49:31So I have a basic car or just a car, but then I have a sports car that does sporty things,
- 49:37right?
- 49:37Maybe it has like paddle shifters or it has like a manual transmission mode that has additional
- 49:42functionality.
- 49:43So I might say, all right, well, the idea is what we're going to do is we're going to
- 49:46create a car and a sports car.
- 49:48And then maybe I want to have a track car that can also take slicks.
- 49:51Like, so it derives from sports car.
- 49:53And the deeper that those get, the more full of the abstractions can break down pretty hard,
- 50:01right?
- 50:01Like, you know, if you model creatures, I've got a living animal and then I've got a bird
- 50:07and then I've got, what do you do with a robot bird, right?
- 50:11Does it drive from bird?
- 50:12That's a hard one.
- 50:13Right.
- 50:13Like it, it has bird like things, but the animal eats, robot doesn't eat.
- 50:17Right.
- 50:18So like if you go too deep, it makes, it's a problem.
- 50:20Right.
- 50:20So that's inheritance, obviously.
- 50:22Composition.
- 50:23Tell us about it.
- 50:24So composition.
- 50:24So if inheritance defines is a relationship.
- 50:27So like a sports car is a car and the car is a vehicle and a vehicle is a thing or whatever
- 50:33machine.
- 50:33Composition defines a, has a relationship.
- 50:37So you can say, okay, a car has an engine or a car has a steering wheel.
- 50:43Right.
- 50:43And it has a transmission.
- 50:44Instead of making a sports car, maybe you just make a car with a sporty transmission.
- 50:49Right.
- 50:50And so the whole thing doesn't have to like, because I don't know, what if you have some
- 50:55kind of truck, but it also has like a manual shifting thing, right?
- 50:58It could, right.
- 50:59You wouldn't have a truck derived from a sports car.
- 51:01That would be weird.
- 51:02Right.
- 51:02But you could easily like interchange the parts and it, it helps really alleviate some
- 51:07of those like deep object hierarchies.
- 51:10I think.
- 51:10Yeah.
- 51:11Yeah.
- 51:11It's, it's basically another tool in your toolbox there for defining these relationships.
- 51:15Because if, if you define everything in terms of a inheritance relationship, then you end
- 51:19up with these unmaintainable, like the, you end up on the dark side of OOP.
- 51:24That's right.
- 51:25And like small changes to like a deep down base class can make absurd things in the end, like
- 51:32a robot that has to eat or something like that.
- 51:34Cause maybe the animal didn't eat at first and that made sense.
- 51:36But now later you realize all the animals have to eat.
- 51:38And then like, well, what do you do about the robot thing that we put there?
- 51:41Like that's where you use multiple inheritances, which is like a whole dutter of can of worms.
- 51:46That's a deep, that's a big can of worms as well for sure.
- 51:48But I, I'm a big fan of composition.
- 51:50I think, I can't remember where I heard, I'm pretty sure the original gang of four design
- 51:54patterns books said prefer composition over inheritance.
- 51:57Yeah.
- 51:59Like you want shallow hierarchies.
- 52:00Yeah.
- 52:01Like you're going to like it's objects and inherits aren't inherently bad, but they're
- 52:05easy to abuse.
- 52:06And so composition is a really way, good way to keep those shallow and interchangeable and
- 52:11small.
- 52:11So yeah, quite, quite cool.
- 52:13I like this one a lot.
- 52:14Wow.
- 52:15Did we really make it to the, all the way?
- 52:16Oh, actually speaking of the gang of four book, I think that might be a recommendation
- 52:20here at the end of the article because we, yeah.
- 52:23Also always give.
- 52:24Yeah.
- 52:24So the article comes with recommended reading, right?
- 52:26Yeah.
- 52:27Yeah.
- 52:27It's got some cool design, design patterns.
- 52:30head first design patterns, clean code, solid principles, list cove substitution principle,
- 52:34all those kinds of things.
- 52:36Yeah.
- 52:36A lot of these apply.
- 52:37It would be remiss of us, I think, to riff so fondly on like an object oriented story in
- 52:44Python without seeing that like a lot of what people do with objects and classes and other
- 52:50languages is simply unnecessary in Python.
- 52:53Right.
- 52:54So there is a little bit of pushback and well, I know you did Java and everything had
- 52:58to be a class.
- 52:59You don't have to build it this way.
- 53:01Right.
- 53:01Like for example, if you have a variable that you need to be basically a singleton and then
- 53:07you want to group a bunch of functions together, you could have a static class that has those
- 53:11in there in like Java or C# or something like that.
- 53:15But you could also in Python just have a module that has a variable and it has functions.
- 53:21And then if you just import that module, you say that module dot the fields or the
- 53:26variables or the functions, that's the same thing as a static class.
- 53:29Right.
- 53:30Yeah.
- 53:30Right.
- 53:30You don't have, and you don't, it saves you a bunch of work and it's, it's more Pythonic.
- 53:35Yes.
- 53:35I guess.
- 53:36Right.
- 53:36Then making everything a class.
- 53:38Yeah.
- 53:38So there, I mean, maybe there's a little bit of, do I really need a class for that?
- 53:43Right.
- 53:43If you're going to create different ones over there, different values at the same time, like,
- 53:47well, probably.
- 53:47Right.
- 53:48But maybe if you're like just trying to group stuff, maybe the modules, right thing.
- 53:50But if you do decide and it does make sense to have a class, this inheritance versus composition
- 53:56thing is super important to understand.
- 53:57Yeah, absolutely.
- 53:58And I don't want to give the impression that like, you know, if you, if you're writing in an object
- 54:02oriented programming state style, that that's somehow superior or like the end
- 54:05all, you know, of, of coding.
- 54:07I don't, I don't think that's, that's actually true.
- 54:09I think the really powerful thing is understanding these tools, like to have a really
- 54:13big toolbox and being able to pick the things that make the most sense.
- 54:17Like a lot of times, you know, when, when I'm writing a program in Python or I'm sketching
- 54:20something out, I, I'll hardly like write any classes depending on, on the use case.
- 54:24Or I found myself, you know, most recently just basically adding like these, like, so I've
- 54:30been working on the real Python platform a lot and I've been writing more function-based
- 54:35codes or procedural code where maybe my data model is class-based, but then I'll have,
- 54:41you know, a module or I don't know, redeeming access codes or coupon codes or something like
- 54:47that.
- 54:47And it basically defines like a really nice high level interview interface to me.
- 54:50These are the five operations you do on coupons or something, right?
- 54:54Yeah.
- 54:54Yeah.
- 54:54And that's all function-based.
- 54:56Yeah.
- 54:56And then internally they, they use classes to kind of represent the data and, and shuffle
- 55:01it around.
- 55:01Probably working with Django ORM or something like that.
- 55:04Right.
- 55:04Yeah.
- 55:04Yeah.
- 55:04Yeah.
- 55:04Instead of cramming that all into a view or actually I prefer, for example, a function-based
- 55:09views in Django instead of class-based views because I don't like sort of the getting the
- 55:12deeper intendation.
- 55:13I would, we could, we could get into all kinds of, disagreements there, but, yeah,
- 55:20just, just want to make sure, you know, that, that I get this across that, I don't
- 55:23think the OOP coding style is, not the one true way that the one true way that this
- 55:30should be one, exactly one way to do things.
- 55:31Yeah.
- 55:32Yeah.
- 55:32But if you're going to do it, like understanding this, this difference between inheritance
- 55:35composition, certainly, it certainly makes sense.
- 55:37I do a lot of what you're recommending there as well.
- 55:39All right.
- 55:39Well, that's our top 10 items, Dan.
- 55:42Yeah.
- 55:42That, that went by super fast.
- 55:45Yeah.
- 55:45It did go by fast, but I think these all have special value and, you know, people might
- 55:49be kicking back.
- 55:51A lot of folks have vacation time around this time of year.
- 55:53You know, they're also thinking of what's coming in the next year in 2020.
- 55:57I mean, first of all, let's just take a moment and say, thank you, Python 2, but goodbye.
- 56:05Yeah.
- 56:05Bye-bye.
- 56:05We'll miss you.
- 56:07The death plot is down to single digit days probably at this point.
- 56:12Right.
- 56:12So that's actually pretty exciting.
- 56:14Yeah.
- 56:14That's a big change, right?
- 56:15Yeah.
- 56:15Yeah.
- 56:16You're right.
- 56:16Yeah.
- 56:16Cool.
- 56:17All right.
- 56:17Well, there's a bunch of articles for people to check out while they're on vacation, got
- 56:21some time away from work.
- 56:22They don't have to, you know, fill out TPS reports all day.
- 56:24Smashed out printer.
- 56:27That's right.
- 56:27Smashed out printer.
- 56:28Awesome.
- 56:29All right.
- 56:29Well, thanks for being here as always.
- 56:31Cool.
- 56:31Yeah.
- 56:31Thanks for inviting me.
- 56:32This is great.
- 56:33You're welcome.
- 56:33I guess I should ask you the two questions before you go.
- 56:35So the two questions are, what editor do you use to write Python code these days?
- 56:40So I've started to use Visual Studio Code a lot.
- 56:43I use Sublime Text.
- 56:46Yeah.
- 56:46It's a pretty similar style of editor.
- 56:49Very similar.
- 56:49Right.
- 56:50Yeah.
- 56:50What I still love about Sublime is just how fast it is.
- 56:53Like there's a noticeable difference in the rendering speed and scrolling around.
- 56:58But the Python integration that VS Code has out of the box is really cool.
- 57:05It's growing and growing all the things it can do.
- 57:07I like it for recording video courses because I can have an integrated shell there.
- 57:12I can have a setup that looks really, really nice, I think.
- 57:14And so I've been doing that a lot recently.
- 57:16And so, yeah.
- 57:17Working out of VS Code.
- 57:19Yeah.
- 57:19Awesome.
- 57:20The other question changing for today.
- 57:22What's next for RealPython in 2020?
- 57:25100 authors?
- 57:26Yeah.
- 57:26That's a big goal of mine.
- 57:27You know, I want to, I would love to have 100 authors published on the site.
- 57:31Authors and instructors as a magical number.
- 57:33And, you know, maybe we'll crack that 3 million visitors.
- 57:37I don't know how many Python developers are out there.
- 57:39Well, I suspect after they listen to this episode, it'll probably be 3 million straight up.
- 57:43It'll be 10 more.
- 57:44For sure.
- 57:46It's going to, yeah.
- 57:47Awesome.
- 57:47Well, best of luck in 2020 and keep up the good work.
- 57:50It's a huge resource for everyone.
- 57:51Thank you.
- 57:52I mean, you know, same to you.
- 57:53Like, it's been so cool just becoming friends with you.
- 57:56And when we first met, which was, I think, like three years ago.
- 57:59Three or four years ago.
- 58:00It's quite a while back.
- 58:01And just being on this journey here together.
- 58:03I really appreciate that.
- 58:05Yeah, absolutely.
- 58:06Thank you.
- 58:06Same to you.
- 58:06It's been fun to be on it together.
- 58:08Awesome, man.
- 58:08All right.
- 58:09Well, catch you later.
- 58:09Bye.
- 58:10Yeah.
- 58:10Bye-bye.
- 58:10This has been another episode of Talk Python To Me.
- 58:14Our guest on this episode was Dan Bader.
- 58:17And it's been brought to you by Linode and Brilliant.org.
- 58:20Start your next Python project on Linode's state-of-the-art cloud service.
- 58:24Just visit talkpython.fm/Linode.
- 58:27L-I-N-O-D-E.
- 58:29You'll automatically get a $20 credit when you create a new account.
- 58:32Brilliant.org encourages you to give the gift
- 58:36of critical thought and knowledge.
- 58:37Visit talkpython.fm/brilliant and grab a gift subscription to help your loved ones finish
- 58:43their day a little smarter this season.
- 58:44Want to level up your Python?
- 58:47If you're just getting started, try my Python Jumpstart by Building 10 Apps course.
- 58:51Or if you're looking for something more advanced, check out our new async course that digs into
- 58:57all the different types of async programming you can do in Python.
- 59:00And of course, if you're interested in more than one of these, be sure to check out our
- 59:04Everything Bundle.
- 59:04It's like a subscription that never expires.
- 59:06Be sure to subscribe to the show.
- 59:08Open your favorite podcatcher and search for Python.
- 59:11We should be right at the top.
- 59:12You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 59:17and the direct RSS feed at /rss on talkpython.fm.
- 59:21This is your host, Michael Kennedy.
- 59:23Thanks so much for listening.
- 59:25I really appreciate it.
- 59:26Now get out there and write some Python code.
- 59:27I'll see you next time.