Latest / Talk Python To Me / #25: Effective Python
Transcript
- 0:00What if you could bottle up all the wisdom and hard-fought experience of many expert Python developers and power up your skills?
- 0:05That's what Brett Slatkin did, and he put it in his new book, Effective Python.
- 0:10This is episode number 25 of Talk Python To Me, recorded Wednesday, August 12, 2015.
- 0:16Welcome to Talk Python To Me, a weekly podcast on Python, the language, the library's,
- 0:46the ecosystem, and the personalities.
- 0:48This is your host, Michael Kennedy.
- 0:50Follow me on Twitter, where I'm @mkennedy.
- 0:52Keep up with the show and listen to past episodes at talkpython.fm.
- 0:56And follow the show on Twitter via at Talk Python.
- 0:59This episode is brought to you by Hired and CodeChip.
- 1:02Thank them for supporting the show on Twitter via at Hired underscore HQ and at CodeChip.
- 1:07It's another week with a book giveaway.
- 1:10And just like last week's, this one is a really excellent one.
- 1:14Make sure you're a friend of the show and you'll be in the running to win the free e-book version of Effective Python.
- 1:20Just visit talkpython.fm, click on Friends of the Show, and boom, winning happens.
- 1:25Well, sometimes, if you're lucky.
- 1:27Now let me introduce Brett so we can get right to the show.
- 1:30Brett Slatkin is the author of Effective Python.
- 1:33He's the engineering lead and co-founder of Google Consumer Surveys.
- 1:37He formerly worked on Google App Engine, the PubSub Hubbub protocol, and managing Google's fleet of servers.
- 1:44Outside his day job, he works on open source tools and writes about software, bicycles, and other topics on his personal website.
- 1:50And today, he lives in San Francisco.
- 1:53Brett, welcome to the show.
- 1:55Thanks for having me, Michael.
- 1:57Yeah, I'm really excited to talk to you about your book and the other stuff you have going on with Python.
- 2:01We're going to talk about this book that you recently released called Effective Python.
- 2:06And I was a big fan of the Effective series back in the C++ days.
- 2:11And so when I saw your book title, I was like, oh, this is going to be awesome.
- 2:14So it's going to be a fun conversation.
- 2:17Yeah, definitely.
- 2:17And I similarly, Effective C++ was the best programming book that I ever had.
- 2:23And so I totally agree with that.
- 2:27So that was 1997 or 1998 when that came out when I first read it.
- 2:31And being able to make the Python version of that was really a great honor for me to be able to write.
- 2:38Yeah, I bet it was.
- 2:39That's great.
- 2:40Before we get into the details of your book, though, maybe we could just talk a bit about how you got to where you are.
- 2:47How did you get into programming in Python?
- 2:49Yeah, so I won't bore you with the super long details of my history of writing code.
- 2:55But I've been writing code since I was about 10 or 11 years old.
- 2:58My first job out of college was at Google.
- 3:02And I showed up for my first day of work.
- 3:06And they said, OK, here's this Python code base.
- 3:10You need to make it better.
- 3:11Here's a book.
- 3:12And Alex Martelli sits right there.
- 3:15Figure it out.
- 3:16So I had seen Python.
- 3:18I hadn't written any Python at all.
- 3:20And I went from basically knowing nothing about Python and then actually writing a book about it in about 10 years, which is pretty funny.
- 3:28Yeah, that's great.
- 3:29The student becomes the master sort of thing, right?
- 3:32Yeah.
- 3:32I hope so.
- 3:33I hope it's worthwhile.
- 3:34Well, I think what was funny is that my first impression of Python was from the BitTorrent code base.
- 3:40Because Bram Cohen had had this post all about Python and how it makes him more efficient.
- 3:44And that's why BitTorrent's so awesome.
- 3:47I don't think people realize that BitTorrent was written by Python.
- 3:50But then like Zope and Plone, I thought were just really, they were code bases that I was very unhappy with using when I tried Python for the first time.
- 3:58And that kind of turned me off.
- 3:59So then when I showed up at Google and they said, OK, you're using Python, I was cautiously optimistic.
- 4:06But it ended up turning out real well.
- 4:09And so I can just go real quick, just the kind of projects that I used Python for at Google.
- 4:15Yeah, people would love to hear that.
- 4:16My first job there was kind of doing janitorial services for data centers.
- 4:23Google has a bunch of machines in their data centers.
- 4:26Those machines have a life cycle.
- 4:28They're built.
- 4:28They're repaired.
- 4:29They break.
- 4:31And I worked on a bunch of the tools to help that life cycle, which are primarily written in Python.
- 4:37And I got to scale that out into Google's kind of worldwide network of data centers, a lot of system level code, a lot of networking, kind of database accessing, all kinds of stuff like that, workflows.
- 4:50So that was my first kind of big role.
- 4:53I did some other things similar to that around security and securing the machines in a data center.
- 5:01And then shortly after that, that was a couple of years.
- 5:04And then shortly after that, I heard of this really cool project that was being created called App Engine that had just started.
- 5:09And I thought it really had a lot of potential.
- 5:14And so I went and talked to that team.
- 5:16I think it was four people at that point, the original founding team.
- 5:19And I was like, what can I do to get on this team?
- 5:22How can I work on this?
- 5:23And in my 20% time, I built the App Engine Dev App Server, which is, I don't know if you've ever used App Engine, but you spend a lot of your time using this development tool to actually write your apps.
- 5:37And so, yes, I built that.
- 5:38And they're like, oh, this is pretty good.
- 5:39And then they invited me to join the team.
- 5:41And then I helped build App Engine out and launch it, which was, so it's, you know, platform as a service, Google's cloud kind of system.
- 5:49Yeah, that's, it's really cool.
- 5:51And was Python the very first language or was it Python and Go?
- 5:55What was it?
- 5:56It launched with just a restricted set, right?
- 5:58Yeah.
- 5:58So Python was the first language.
- 6:00Java came like a year and a half or two years later.
- 6:02And then, and then Go came a little bit after, like maybe two, two or three years after that.
- 6:09I think the first language is actually supposed to be JavaScript, server-side JavaScript in the old Netscape, LiveScript scheme of things.
- 6:17But in 2008, that seemed like a completely ridiculous proposition, which is pretty funny looking at all the Node.js stuff that's happened in the last few years with V8.
- 6:25This is way before V8.
- 6:27JavaScript is still really slow.
- 6:29And so anyway, so they went with Python because it was one of the main languages that Google had used.
- 6:35And Google had a lot of expertise in Python in general.
- 6:37So on the App Engine team, I spent a lot of time working on Python infrastructure, Python APIs,
- 6:43just kind of the feel of what it was like to write apps on top of App Engine using Python and fix a lot of bugs,
- 6:50vetted new APIs to go out to make sure they felt good, built infrastructure around task queues and MapReduce and offline processing and all kinds of different things.
- 7:01Did that for a few years.
- 7:04And then also started this project called PubSubHubbub in there, which was a real-time RSS project for making RSS feeds real-time,
- 7:14which is kind of hilarious also in hindsight now since that's pretty – it's kind of like saying I made something to design pogs or something like that.
- 7:22It's kind of old.
- 7:23Yeah, that's pretty funny.
- 7:25But that was the Google Reader days and all that kind of stuff, right?
- 7:27Yes, the good old days.
- 7:29Yeah.
- 7:29I kind of miss that thing still.
- 7:30I do too, all the time.
- 7:33I've been using News Blur recently, which I believe is also a Python app written in Django.
- 7:38But, you know, anyway, I miss Reader.
- 7:40Yeah, definitely.
- 7:42So that is a bunch of really cool stuff.
- 7:44And we might have to come back and talk about that at some later date in more detail.
- 7:49That'd be really fun.
- 7:49But let's talk about your book today.
- 7:51It's called Effective Python.
- 7:53What's the subtitle?
- 7:55It's 59 Specific Ways to Write Better Python.
- 7:58It's kind of based in this – the heritage of the Effective series, which, as we kind of hinted at the beginning,
- 8:04I think that started out with Scott Myers and Effective C++, right?
- 8:08Yeah, he invented the format.
- 8:10And, you know, he's really the guy who came up with this way of educating people.
- 8:17And all the other books are in his style.
- 8:20Yeah, that's cool.
- 8:20And so I remember when I was learning C++, I could sort of do stuff with it.
- 8:25You know, I could write code and so on.
- 8:27But after I read his book, I felt like it really took my understanding and effectiveness to a new level.
- 8:34And so you're kind of trying to bring this to the Python developers, right?
- 8:37Definitely.
- 8:39Yeah, that's the goal of the book.
- 8:41It's a bit of an audacious goal, but yeah.
- 8:44Yeah, I mean, I think it's really simple is that, like, I read an introductory Python book.
- 8:49This Effective Python is the book I would have given to myself as a second book if I had had the chance.
- 8:54So there was a gap in my knowledge that took me years and years and years to fill.
- 8:59And this book is kind of a way to shortcut and get all that practical knowledge without having to actually pay the dues.
- 9:05So I wish I had had this book when I was starting out.
- 9:09You know, we talk a lot about the concept of Pythonic code and idiomatic Python and stuff.
- 9:14And there's a lot of that concept in there.
- 9:16You know, like, this is the way you should do things in Python, even if you already know if you could accomplish it using your old idioms from, say, Java or C# or something.
- 9:26But then there's another part, another angle to it that's just sort of broadening your horizon, I think.
- 9:35So it's not just about writing Pythonic code.
- 9:37And I'm thinking of things like how you would use, say, subprocess to manage child processes and parallelism from your Python app, right?
- 9:47That's not technically a Pythonic thing, but it definitely ups your game and what you can do.
- 9:51Yeah, I think, you know, a lot of the advice is pure language construct kind of stuff.
- 9:58And then other things are like, yeah, the subprocess is item.
- 10:01But, you know, it's important to remember that one thing that they say about Python is, you know, batteries are included, right?
- 10:06And so, you know, the difference between Python as a language and Python as an ecosystem or Python as a set of libraries that you can use.
- 10:15When people think of Python, they think of all of it together, both the syntax, the language features that it has, and then the libraries that you know you can rely on to always be there.
- 10:23So those are tools you should have in your toolbox that are part of being a Python programmer, just like, you know, the collections API if you're a Java programmer, because it's basically all you write all the time.
- 10:34Yeah, absolutely.
- 10:35I have many friends that work in other languages, and they often want to compare their language to Python.
- 10:43And like you said, I think that's not even a conversation you can begin to have if you don't think about the entire standard library and the 60,000 PyPI packages.
- 10:54And, you know, you've got to take it as a whole, right?
- 10:56It's not just, here's how you do properties here and properties there.
- 10:58So this is either better or less good, right?
- 11:02Yeah, totally.
- 11:02I mean, a lot of these things, you have so much, I like to use the word leverage, you know, to describe, you get to stand on the shoulders of giants.
- 11:10There's a lot of different ways to say it.
- 11:11But yeah, things like NumPy, as an example of a library, it's a whole ecosystem unto itself.
- 11:17And trying to do the equivalent in Java or C++ is extremely difficult.
- 11:22Yeah, that's for sure.
- 11:24So I thought one way that would be fun to have a conversation about your book is kind of go from section to section or chapter to chapter and pick out a few interesting pieces of guidance from each one of them.
- 11:36Yeah, definitely.
- 11:37Yeah, cool.
- 11:38So you broke your book into six parts, and we'll just take them one at a time.
- 11:42So the first one is this concept of sort of the libraries and Pythonic thinking, right?
- 11:48Yeah, that's the first part.
- 11:49It's actually eight separate chapters is how many there are, because it keeps going.
- 11:53But yeah, the first one is Pythonic thinking.
- 11:58Excellent.
- 11:59So why'd you start with that?
- 12:01Yeah, I think that it's kind of like the strange universe of Python syntax.
- 12:07You have to get used to doing things.
- 12:09Even simple expressions like, I remember when I first started writing Python, and the not operator, as opposed to using the bang or exclamation point, getting used to where that not goes.
- 12:19And things like is not, as opposed to, you could do A is not B, or you could do not A is B.
- 12:26And, you know, understanding that the Pythonic way is A is not B. That's how you'd say it.
- 12:30So you really need this base to start with, so that all the other things make sense or are in context.
- 12:37Right. I also think it's probably a good way to kind of shock the system a little bit to prepare them for, like, this is a different world, probably, than you're coming from.
- 12:45Yeah.
- 12:46And so get prepared to think differently.
- 12:48Yeah, it's to open, I think it's a good way to say it, because I think it's, if you try to fit it into the way you're writing other languages, you're going to have a bad time.
- 12:56And you really need to embrace the Pythonic way of doing it.
- 13:00I had one person told me once that my C++ code looks like Python.
- 13:04I thought that was a really great compliment, I guess.
- 13:08But you don't really want your Python to look like C++, right?
- 13:10Yeah.
- 13:11Absolutely.
- 13:12Cool.
- 13:13So the very first thing that you talk about, literally the first piece of guidance, is to know what version of Python you're using.
- 13:21And I do a lot of training in Python, and it's always a problem.
- 13:25Someone's always running the wrong version of Python, or even worse, they're trying to use a package and they install it into the wrong version of Python,
- 13:33and then they're running the right one or something like that, right?
- 13:35Yeah, that's a big problem, especially with the Python 3 move that's going on.
- 13:39You know, you can get confused really easily.
- 13:41And then a lot of the features that people like to use, like even with statements, are actually more recent developments.
- 13:46So if you're on some old version, some versions of macOS are like running Python 2.5, and you don't know it,
- 13:52and you try to do simple things like a with statement, it doesn't work.
- 13:54And so that can be very surprising.
- 13:57So it's always good to check your assumptions.
- 13:58Yeah, absolutely.
- 13:59So sort of level set, all right, we all know what we're talking about.
- 14:02Now we can move forward, right?
- 14:03Yeah, exactly.
- 14:05So what I think probably a lot of people are familiar with, but some are not, is sort of working with sequences.
- 14:12And you say you should prefer using list comprehensions over like chaining a map and a filter call together.
- 14:18Yeah.
- 14:21Yeah, so I think if you, yeah, I think the story, so it's interesting, because if you look at the history of Python, people will talk about how, oh, I like Python, because it's kind of functional, but it's kind of object oriented, and it's kind of scripty.
- 14:33And so you'll still see examples or guides today.
- 14:36You'll be searching around the internet, and you'll find some old guide on active state from like 2006.
- 14:40And it's like, here's how you should use map and filter.
- 14:42And, or even 2003, like, you know, a long time ago.
- 14:47And those are useful tools, sometimes they're useful, but the list comprehension syntax is just so much more pithy.
- 14:54I think that Python over the years has added more and more tools to maximize the readability of code, and to minimize the visual noise, the extra parentheses and brackets and various symbols that you need to express something.
- 15:07And so I think that map and filter are kind of just antiquated tools that are in the language, because they're hard to take out, because they're, you know, kind of keywords, built in functions.
- 15:18If I had my way, I would just take them out, because I think list comprehensions are better.
- 15:22This episode is brought to you by Hired.
- 15:36Hired is a two-sided, curated marketplace that connects the world's knowledge workers to the best opportunities.
- 15:42Each offer you receive has salary and equity presented right up front, and you can view the offers to accept or reject them before you even talk to the company.
- 15:52Typically, candidates receive five or more offers in just the first week, and there are no obligations, ever.
- 15:58Sounds pretty awesome, doesn't it?
- 16:00Well, did I mention there's a signing bonus?
- 16:02Everyone who accepts a job from Hired gets a $2,000 signing bonus.
- 16:06And as Talk Python listeners, it gets way sweeter.
- 16:10Use the link Hired.com slash Talk Python To Me, and Hired will double the signing bonus to $4,000.
- 16:19Opportunity's knocking.
- 16:20Visit Hired.com slash Talk Python To Me and answer the call.
- 16:34But yeah, the main thing is that, you know, if you have two ways of doing something, I think the Pythonic way of doing it is always the more clear and more explicit and obvious way of doing it.
- 16:45And so yeah, so that's why I think list comprehensions are definitely the way to go.
- 16:48Yeah, that's cool.
- 16:50I totally agree.
- 16:51It's not exactly a more declarative way of programming, but it's closer, right?
- 16:56That's nice.
- 16:57Yeah, it's more obvious.
- 16:58Sort of related to that, one of your other pieces of guidance was that you should use generators for large list comprehensions.
- 17:05Yeah.
- 17:06It's so easy to switch from one to the other, but when should I use one?
- 17:09When shouldn't I?
- 17:10What's the story of that?
- 17:11Yeah, so I think that, you know, Python can use a lot of memory is one big thing.
- 17:16And depending on what you're trying to do, if you're dealing with a small data set that entirely fits within memory, then you don't have to really think about this.
- 17:24You can just read everything as a list and just work on lists.
- 17:27So if you're reading a file, like a CSV file, and you want to deal with it line by line or something like that, then reading the whole thing into memory is fine.
- 17:35But what always happens is you end up wanting to do something a little bit bigger than you expected, especially with a lot of the data processing stuff that people are doing in Python these days.
- 17:44And so I'm trying to change the culture a little bit to say, hey, why not use a generator if you can?
- 17:52Because if you use a generator, then all of these memory problems go away.
- 17:57A generator returns one item at a time.
- 17:59It doesn't fully materialize the list.
- 18:01So the total memory space that's occupied is just the last thing you return from the generator.
- 18:07The rest of it gets cleaned up, garbage collected.
- 18:10Yeah, that's fantastic.
- 18:11Especially if you're like chaining one to another to another, and they're kind of building up.
- 18:17It's really efficient.
- 18:19Yeah, and to that point, I mean, I think that if you start by at the base level, like if you want to switch to generator code, it's difficult because you have to, you have to,
- 18:27put generators all the way down to the leaves of your call stacks.
- 18:30But if you start with generators at the leaves, then it's very easy to start saying, hey, you know, I'm going to turn this into a streaming generator.
- 18:35And so creating those cascades of generators becomes very straightforward.
- 18:39And so you can get quick, you know, very fast executing code that's easy to follow and uses a low amount of memory very, you know, very cheaply.
- 18:48And it's very readable.
- 18:50So that's why I suggest that.
- 18:53So the final language one that I wanted to sort of point out is something that I always thought was weird is the whole concept of the else statement on a loop.
- 19:04Yeah.
- 19:05And something I recently learned is that try except finally also supports else.
- 19:12It does.
- 19:13Yeah.
- 19:13Yeah.
- 19:14And you have really interesting guidance.
- 19:15You say, you know what, these, this else statement on loops, maybe not so much, but on exception handling, it's very cool.
- 19:20It's like an alternative to the catch.
- 19:22Yeah, definitely.
- 19:23Yeah.
- 19:24So I think else, else makes a lot of sense for try except finally, because you're basically saying, you know, try to do this.
- 19:31If an exception happens, do this.
- 19:33And if no exception happens, then do this other thing.
- 19:36And that's what the else block is on a, on an exception, kind of try except.
- 19:40and so that makes things really clear, clearly delineated what will and will not happen inside your exception handling.
- 19:45and when you're doing exception handling, you want the try block to be as small as possible to narrow what you're catching.
- 19:52So that, that exceptions you didn't plan to catch are raised back up.
- 19:56That's, that's like a really important thing.
- 19:57Yeah, that makes sense.
- 19:58And the other thing is, you know, you might think, well, just the last bit of code in your try bit, your try try block could be what would go in the else statement, but that doesn't account for like early returns.
- 20:11And so, you know, if you were to do, try to do some stuff, if this, oh, just return, it would still run that else, but then you'd have to be really careful, you know, trying to put that cleanup all over the try.
- 20:22So yeah, it's really nice.
- 20:23Yeah, it's nice.
- 20:24And yeah, you can put like final cleanup stuff in the finally, and that'll always run if you have an early return.
- 20:29And if you have an else with an early return, that'll also still run the finally.
- 20:32So it's, it's super nice.
- 20:34Going to that back to that for loop part of it.
- 20:36Yeah, I think that's one of the big things.
- 20:37Like when people first learn about that in Python, they're like, oh, this is so great.
- 20:40I can, I can use it for doing this and that.
- 20:43And it's, there's really, yeah, I think it's something to avoid.
- 20:47It's kind of like, it's a shiny new toy and you want to use all the different parts of it for you, you know, and you have to like stab yourself in the eye before you realize that you're getting, that wasn't a good idea.
- 20:57That thing hurts.
- 20:58Yeah, it hurts.
- 20:58Like, oh, it's short.
- 20:59It's pointy.
- 21:00I shouldn't touch that.
- 21:00And I was talking to, I was talking to Guido about this one in particular because he said, you know, cause I was asking him what he thinks about this one.
- 21:10Cause it's kind of, it's kind of tough.
- 21:12I had worked with Guido on App Engine for a few years and, so, and I see him at PyCon from time to time.
- 21:17And so, you know, I felt bad by saying like, hey, you shouldn't use this part of the language.
- 21:20I just, you know, wanted to make sure it wasn't ridiculous to him.
- 21:23And, you know, he said that it's actually an implementation detail of how the Python, the CPython runtime is implemented.
- 21:29the way that the for else block, the else with loops works has to do with the way these go to statements actually work in the Python interpreter.
- 21:37and so if you, if you, if you wrote that code, then it makes perfect sense because the else has to do with the way the certain switch or go to statement works.
- 21:47it's switch statements.
- 21:48Sorry.
- 21:48It's not a go to thing.
- 21:49It's a switch.
- 21:49And, but if you don't have that mental model, then it makes no sense.
- 21:53And, you know, I think that, so for, for Guido and maybe other people who've hacked on the core, they just get it and it makes sense to them, but everyone else they have, it does the opposite of what you would expect.
- 22:04And so just because of that, I think it's too sharp and I think it's something you should avoid.
- 22:08Talk Python To Me is partially supported by our training courses.
- 22:13Do you want to learn Python, but you can't bear to subscribe to yet another service at Talk Python Training?
- 22:19We hate subscriptions too.
- 22:20We hate subscriptions too.
- 22:21That's why our course bundle gives you full access to the entire library of courses for one fair price.
- 22:26That's right.
- 22:27With the course bundle, you save 70% off the full price of our courses and you own them all forever.
- 22:33That includes courses published at the time of the purchase, as well as courses released within about a year of the bundle.
- 22:40So stop subscribing and start learning at talkpython.fm/everything.
- 22:46All right.
- 22:47So the next chapter was functions and there's a lot of good stuff in there.
- 22:50One of them that I'm a fan of is the whole sort of concept of it's easier to ask for forgiveness than permission.
- 22:57Okay.
- 22:59And, you know, that sort of manifests in your recommendation of saying prefer exceptions rather than returning none from functions.
- 23:05Yeah.
- 23:06Yeah, definitely.
- 23:06Yeah, this one I think that people, they're always looking, I don't know if you've ever heard of like a tribool.
- 23:13There's always this joke about a tribool.
- 23:15It's a Boolean value of three, you know, values, tribool.
- 23:18People are always dying for a tribool because it's, you know, it's true or it's false or it's some exceptional case that's neither true or false.
- 23:24And none in Python ends up playing that role a lot of the time.
- 23:28And that's a problem because in Python, both false and none evaluate false.
- 23:37They're falsy values.
- 23:38And so what ends up happening is it introduces a lot of bugs into your code because you say, hey, you know, x equals this function call.
- 23:45And then if x, then do this other thing.
- 23:48Or if not x, do this, then there's an error.
- 23:51But if you're returning none, then that if not x kind of statement is going to run no matter what.
- 23:59And so my whole point, I've been hit by this bug in production a whole bunch of times.
- 24:03I had to learn this one the hard way over the course of many years.
- 24:07And I'm still managing a code base that has a bunch of this in it and trying to take it out.
- 24:13And so my advice here is if you have anything exceptional, just always raise an exception.
- 24:16That's what exceptions are for.
- 24:18I think people coming from other languages are used to exceptions costing a lot of CPU time or somehow, you know, cause a lot of cache problems.
- 24:28And that's true for C++ and other languages.
- 24:31But in Python, raising exception is a little bit of cost to it, but it's not enough to matter.
- 24:36And the clarity is worth it.
- 24:38Not enough to introduce bugs into your code, right?
- 24:41Yeah, exactly.
- 24:42It's like, okay, well, it's fast, but it doesn't work correctly.
- 24:44It's like, all right, well, if that's what you want, then that's fine.
- 24:46Yeah, that's not a trade-off you want to make, right?
- 24:49Yeah, not the right trade-off.
- 24:50Sure.
- 24:51So another one you had around functions that I thought was good advice was if you're going to return a lot of data, just make that function a generator rather than returning a list.
- 24:59Yeah, and this kind of goes hand in hand with, you know, generator statements that I was talking about before.
- 25:08I think I kind of covered both of those when I was talking before.
- 25:10So, you know, generator expressions, there's list comprehensions, which, you know, are a fastest way of doing map and filter on lists.
- 25:17Then there's generator expressions, which is a way of doing exactly the same thing, but the data is generated one at a time.
- 25:22And then a generator function is just a, it's not just a one-liner, it's like a full function that does this.
- 25:28And that's, so what I was talking about before, I think I kind of conflated both of those together.
- 25:32Yeah, I think just having functions that return, that are generators, like I was saying, lets you kind of start with the leaves and move up to make things streaming.
- 25:39Yeah, and it's so easy to just throw in a yield, you know, instead of list.append or whatever, right?
- 25:47Yeah, exactly.
- 25:47It's very clear.
- 25:48And what's interesting is that, you know, JavaScript and other languages are adopting the yield semantics because it's such a powerful tool that people love to use, which is really great.
- 25:58And I'm sure Python stole it from something else.
- 25:59I actually don't know exactly where it yields from originally, but it's a really great tool.
- 26:03Yeah, it's really great.
- 26:05And it's one of those that I find that a lot of people, they haven't taken the time to really learn it and appreciate it.
- 26:12They know it's there and then they just kind of ignore it, right?
- 26:15But knowing, sort of raising the awareness is great.
- 26:18Yeah, definitely.
- 26:19And it should be the default.
- 26:21I think you should just always, you should like plan to yield.
- 26:24Plan, like if you're returning and it's not, if you're returning a sequence, like question what you're doing.
- 26:29Yeah, exactly.
- 26:31The thing better be pretty short.
- 26:33So the last one I want to talk about in functions, which I haven't necessarily decided my feelings on it yet, but is if you use keyword arguments, that can help in the expressivity and clarity of functions.
- 26:47Yes.
- 26:48So I think the actual recommendation was to use just keyword arguments if you get a chance sometimes, right?
- 26:55Go ahead.
- 26:56Yeah.
- 26:56Maybe speak to that a bit.
- 26:57Sure.
- 26:57So, well, I was curious what part you don't necessarily agree with because I'm curious.
- 27:02So, yeah, I mean, because I have a few different parts to my advice, but yeah, keyword arguments are extremely powerful.
- 27:08They let you be explicit about your intention.
- 27:13And yeah, I think that using them in general for optional parameters is really important.
- 27:21So if you have a function that takes an optional flag, then you should always use, you know, keyword argument is a great way to do that.
- 27:26No, I was going to say that I totally agree with.
- 27:28I think where there's an optional thing, it definitely helps because it's not part of what you expect to pass all the time.
- 27:36Right.
- 27:36Yeah, because Python doesn't have polymorphism like other languages.
- 27:39So in Java, you can define the same function name that takes three different sets of parameters.
- 27:43You know, C++ can do that too.
- 27:44And in Python, you can't do that.
- 27:46So the only way to deal with this is to basically add additional optional parameters to one function and have it kind of deal with the various types of input or define a totally different function of the different name, which can get verbose.
- 27:57Right.
- 27:59Yeah, I'm not sure I disagree with you.
- 28:01I just haven't fully internalized that one yet.
- 28:03Yeah.
- 28:03So the use case that I was thinking of is if you have some kind of rich IDE, something like PyCharm or Python tools for Visual Studio or something, and you hit open parenthesis and there's like a nice listing of all the parameters without even looking at the docs, which for optionals, I think that still does show up.
- 28:20But if you just do like the star star KWRs.
- 28:23Oh, yeah.
- 28:23Then you got a problem.
- 28:24Then it's really like, okay, what the heck can I pass?
- 28:28Yeah, no, that's totally true.
- 28:29So star star KWRs, which basically is a catch all.
- 28:33It's you catch any keyword arguments no matter what they are, including garbage.
- 28:36It can be a problem.
- 28:37And this is one of the things that I've tried really hard in the book to do, which is I provide advice that applies both to Python 2 and 3.
- 28:46So it's not a Python 2 book.
- 28:48It's not a Python 3 book.
- 28:49It's like the most overlapping subset that I could find of both.
- 28:52So it should be relevant to everyone.
- 28:55And this is a great example.
- 28:56Python 3 has specific language features that would make it so your IDE will continue to work properly, whereas Python 2 does not.
- 29:04So in Python 2, you can't say these arguments can only be passed by keyword.
- 29:10And you want to do that in situations where you're passing two integer values and you don't know which is which.
- 29:16And so you want to use the keyword part in the function call to make it really clear that, like, hey, this is the numerator and this is the denominator.
- 29:23And it's not the other way around.
- 29:24So here's a label in the function call.
- 29:28Numerator equals 5 and denominator equals 10 or something like that.
- 29:32And you want to enforce that behavior so that people can't call it by just passing 5 and 10 or 10 and 5 on accident.
- 29:37And so in Python 3, you can just add this star into the arguments list and then that's enforced by the compiler and everything's great.
- 29:46And in Python 2, you can't do that.
- 29:47So that star star kwrks is a way to deal with that.
- 29:50And you're right.
- 29:51It breaks your IDE.
- 29:52It makes it harder to understand the documentation.
- 29:54You have to make that tradeoff for you and say, hey, how error-prone is this function?
- 29:58Is it worth doing this, you know, having these optional parameters that are in this way?
- 30:04And, yeah, maybe there's a better design that you could have, maybe a helper class that would be a better way to approach it than having kwrks, star star kwrks, sitting there.
- 30:11Right.
- 30:12It's definitely a cool language feature.
- 30:13It's just I think sometimes it gets overused and you're like, okay, I've got to basically keep the documentation up for a while so I know what my possibilities are, you know?
- 30:21You're totally right.
- 30:22I would say don't use star star kwrks unless you're doing something like this.
- 30:27I think it's one of the few times you should use it.
- 30:30There's some other glue kind of infrastructure times that are good to use it if you're doing, like, generic wrappers of functions and stuff like that.
- 30:36But in general, I try to stay away from it.
- 30:38And I'm really happy that Python 3 has this extra forcing keyword arcs feature.
- 30:43Yeah, that's cool.
- 30:44Okay, then I definitely agree with you.
- 30:46Okay.
- 30:47Thanks.
- 30:47This episode is brought to you by Codeship.
- 31:05Codeship has launched organizations, create teams, set permissions for specific team members, and improve collaboration in your continuous delivery workflow.
- 31:14Maintain centralized control over your organization's projects and teams with Codeship's new organizations plan.
- 31:19And as Talk Python listeners, you can save 20% off any premium plan for the next three months.
- 31:25Just use the code TALKPYTHON, all caps, no spaces.
- 31:28Check them out at Codeship.com and tell them thanks for supporting the show on Twitter where they're at Codeship.
- 31:40So let's move on to classes.
- 31:41One thing that Python supports is multiple inheritance.
- 31:46And speaking about, oh, that's sharp, that hurts, is I did a lot of C++ and even COM with insane templating, multiple inheritance.
- 31:56And I just, I kind of prefer single inheritance and just keep it really simple.
- 32:03And so you were, you're saying that to some degree and you're saying, look, this multiple inheritance stuff should be used for mix-ins.
- 32:09Yeah, definitely.
- 32:10Yeah.
- 32:11So I.
- 32:11Can you tell people what you mean by mix-ins in this case and like how that would go?
- 32:15Yeah.
- 32:16So I think that a mix-in to me is, is a set of functionality that you can add to a class.
- 32:22You can add to any class.
- 32:23So helpers for serialization, helpers for logging, helpers for, you know, doing some kind of introspection on functions and stuff like that.
- 32:34Those are the mix-ins where you're like, hey, I have this class.
- 32:37Wouldn't it be nice if it automatically logged every function call or something like that?
- 32:40Or every attribute access.
- 32:41Let me, let me, let me inherit from this mix-in utility to do that for me.
- 32:45So I think that those are the times where you want to use multiple inheritance, where the class structure doesn't actually matter.
- 32:52It's more like aspect-oriented programming or something like that, where, which I'm not necessarily a huge fan of, but I'm just trying to say that it's nice to be able to kind of compose functionality.
- 32:59And so mix-ins are a way of doing composition with class inheritance.
- 33:05If there were another way to express that composition in Python, that'd be great.
- 33:09But the tool that we have is, is multiple inheritance.
- 33:12Yeah.
- 33:13And I have seen some really beautiful mixing code that, that when done right, right, is nice.
- 33:18Yeah.
- 33:19When it's done correctly, it's, it's really, really nice.
- 33:21And, and it doesn't, it's not brittle.
- 33:24I think a lot of the time, multiple inheritance is, is really brittle and it breaks in weird ways when you refactor it.
- 33:29And mix-ins are built not to be brittle.
- 33:32And so that's why it works out.
- 33:33So it's about composition, primarily.
- 33:36Nice.
- 33:37So let's move on to the next section, meta classes.
- 33:40Yeah.
- 33:41And in there, one thing that was sort of stood out to me was you're talking about that you can register class existence with the meta class.
- 33:49What's the story of that?
- 33:51Yeah.
- 33:52So, you know, meta classes are like the sharpest tool you can poke yourself with in Python.
- 33:57And it's kind of like, once you use it enough, Python enough, you're like, okay, I'm going to try out these meta classes thing.
- 34:02And maybe you read Eric Raymond's thing about meta classes and some email filtering thing he wrote with them and how awesome that was.
- 34:10And you realize that essay is from 12 years ago and it's worth to think about that again.
- 34:14But it's a really powerful tool.
- 34:18I have three different kind of main ways I think you should use it in Python.
- 34:22I don't think you should use it in other ways unless you really know what you're doing.
- 34:25And the registration is one of the big ones.
- 34:28So it's really nice to know, you know, if you're creating infrastructure and you're creating, you know, classes to represent database tables or sensors that self-register,
- 34:38a lot of that kind of like, you want the program to kind of sign itself up and initialize itself up so you don't have to write a lot of boilerplate to say,
- 34:45oh yeah, hey, remember, configure this sensor, configure that sensor, configure this database row.
- 34:50You know, you have a lot of programs end up having these main functions that are just like lists of registration calls for 100 lines of registration.
- 34:57And then it says go after that.
- 34:58And so meta classes give you a really nice way of saying, hey, anytime anyone creates a class,
- 35:07it's part of this hierarchy, register it in a central database of classes or central, you know, dictionary of classes so that when I start my program,
- 35:15I can go through and do all the housekeeping I need to do for initialization.
- 35:20So that's one thing, lets you do initialization really easily.
- 35:23And it also lets you do lookups really easily.
- 35:25So you say, hey, you know, is there a class that does this in the system?
- 35:29Yes, there is.
- 35:29I know exactly where it is.
- 35:30It's right here.
- 35:31I've already imported it.
- 35:31I've already looked at it.
- 35:32I know what it's capable of.
- 35:34So anytime you see yourself doing that pattern where you have one of something now and you're going to have 50 of them later and you need a registry of those things,
- 35:41there's no reason to explicitly register things.
- 35:45You should always just have them automatically register themselves so that it's less error prone.
- 35:49And that's the big thing that I'm trying to kind of advise you to do here.
- 35:54It's, you know, we're humans.
- 35:55We leave things out all the time.
- 35:58And so helping people make fewer mistakes is really important.
- 36:02And so metaclasses are a great way of helping people make fewer mistakes.
- 36:05And that's what that item is specifically about.
- 36:09Nice.
- 36:10The other sort of topic you talk a little bit about there is attributes.
- 36:15I think you talk about like private versus somewhat private, you know, the sort of underscore versus double underscore attributes in there.
- 36:23Is that right?
- 36:23Yeah, I think it's a common thing also that people have when they come from other languages that have like strict definitions of public and private.
- 36:29And, you know, Python doesn't have those things.
- 36:31It has kind of best equivalents of that.
- 36:35And the gist of it is, you know, you should just make everything public by default in almost all cases.
- 36:42Because people are going to go in there and reach in and make things that are private, public anyway.
- 36:46There's some nuance to it, but that's the gist of it.
- 36:49And Guido refers to this as, you know, we're all consenting adults.
- 36:53You know, you should let people reach into the class and use it however they want if they want to.
- 36:59As long as you know you're getting yourself into trouble, then, you know, if you're willing to take on that risk, then it's up to you.
- 37:04So, yeah, I think the whole idea here is that Python is a dynamic language.
- 37:08So things are mutable and more fluid.
- 37:09So you don't have to have this kind of draconian public-private enforcement that maybe Java programmers have.
- 37:16It's interesting that other languages are so focused on not letting people do things by default,
- 37:22where Python is focused on really letting anyone do anything with a class by default.
- 37:26Yeah, that's an interesting just language philosophy statement altogether, isn't it?
- 37:31Yeah, it is.
- 37:32And some people say that's why Python gets difficult for really large projects,
- 37:35because that's why defaulting to closed is good.
- 37:39It's because once the project's a million lines of code, then, you know, it's too late.
- 37:42I understand that.
- 37:44But I think, you know, a million line Python project is a very large program.
- 37:48A lot of people have never worked on something that size and probably never will.
- 37:50So it's kind of like one size does not fit all.
- 37:53Yeah, that's a good point.
- 37:55I mean, I see a lot of people that learn design patterns and other things, and they just want to apply them.
- 37:59Exactly.
- 38:00To whatever, right?
- 38:01But these design patterns maybe make sense on very large scales or certain circumstances, right?
- 38:06Absolutely.
- 38:06And that's why I think all the advice needs to be in context.
- 38:09You know, okay, you're giving me this advice.
- 38:10Who are you?
- 38:12What are you doing?
- 38:12How big is the code base?
- 38:13You know, like, how often do you have to do it?
- 38:15Like, I need to know those things because your design constraints are different than mine.
- 38:18So.
- 38:19Right.
- 38:20How similar are we?
- 38:21Yep.
- 38:21So one of the sections I really liked, and I'm looking forward to digging into it more,
- 38:27is the concurrency and parallelism section.
- 38:30Yeah.
- 38:31And you draw an interesting distinction between what you're calling concurrency and parallelism.
- 38:36Can you maybe speak to that first?
- 38:38And I think this goes back to, there's this great talk that Rob Pike, who's one of the
- 38:42creators of the Go programming language, a language who also works at Google, he did called concurrency
- 38:47is not parallelism.
- 38:48It's a great, great talk to check out.
- 38:51But yeah, it's basically, you know, concurrency is a programming pattern.
- 38:54It's a way of doing multiple things at the same time and having tools to let you do that at the programming level.
- 38:59So threads are one of those tools.
- 39:00Coroutines are one of those tools.
- 39:02And then parallelism is actually running two lines of execution on a processor at the same time.
- 39:07And that's not necessarily a programming tool.
- 39:11It's just the way that the program runs.
- 39:13And Python is great at doing concurrency style stuff.
- 39:18But Python can actually do, cannot do parallelism because of the global interpreter lock, which I'm sure people listening to this have probably heard of.
- 39:26But that's one of its big shortcomings as a language.
- 39:29Concurrently, you're thinking of maybe I'm going to make two web service calls at the same time and I can wait for one to come back.
- 39:37But parallelism is I'm trying to compute this financial algorithm and it's just a computational thing.
- 39:45And breaking that up into steps and trying to run that with threads is not really going to do much for you, right?
- 39:50Yeah.
- 39:51Or if you're trying to decode two frames from a video stream simultaneously on two different CPU cores, you can't do that in Python without actually going down to the C API.
- 40:00Whereas asynchronous things, you can do it in parallel.
- 40:04You can even run threads where that computation looks like it's happening in parallel, but it's actually not.
- 40:09It's happening concurrently.
- 40:11So you can't increase your throughput of computation with threads or any kind of concurrent infrastructure in Python.
- 40:19You can't get parallelism, cannot get parallelism that way.
- 40:23Right.
- 40:23So your first piece of guidance was to use the subprocess module to manage child processes.
- 40:29And those might be Python subprocesses or they might just be other executables, right?
- 40:34Yeah.
- 40:35Yeah.
- 40:36And that's a cheap way to get some parallelism because, you know, at the system level, multiple processes can be doing multiple things on multiple cores.
- 40:43So you can really take advantage of your computer that way.
- 40:45Yeah.
- 40:46Nice.
- 40:46Another one that you had was to use threads for blocking IO, but to avoid threads for CPU parallelism.
- 40:52And that kind of is a little bit what we were talking about, right?
- 40:55Yeah.
- 40:56Your web service calls exactly that.
- 40:57So you can do a web service call in one thread, another web service call in another thread, and they will happen concurrently.
- 41:04But they actually won't process in parallel.
- 41:07So it's great for kind of blocking tasks or IO bound tasks, threads are, but they don't actually help you go faster.
- 41:15Right.
- 41:15So verify my mental model here.
- 41:17I think I recall that if I have a thread in Python and it does some blocking IO, that thread will release the global lock, right?
- 41:28Exactly.
- 41:29Yeah.
- 41:29So you can use threads to avoid waiting.
- 41:32It's basically all you get.
- 41:33But you can't use them to.
- 41:35And so the gill, yeah, will unlock and then another thread will start running.
- 41:39And that's nice.
- 41:41And that's what threads are good for.
- 41:42But that's as far as it'll go.
- 41:45Right.
- 41:45Sort of the Node.js style of parallelism, maybe.
- 41:47Yeah.
- 41:48It's very similar, actually.
- 41:49Node has a lot of the same constraints and problems.
- 41:51It only has one executing thread at any time.
- 41:54Okay.
- 41:55So another one was to use or consider coroutines for running many functions concurrently.
- 42:00How's that look?
- 42:02Yeah.
- 42:02Yeah.
- 42:03This is my favorite item in the book, item 40.
- 42:05Yeah.
- 42:07I implement Conway's Game of Life as a set of coroutines.
- 42:09I would say if you understand this one, then you've understood the Xenopython pretty
- 42:14well.
- 42:15And it's basically just trying to say that you can express very complicated, high-level
- 42:21ideas of the way that things should interact.
- 42:23Whole system flows should work, workflows, using coroutines in this really abstract way that's
- 42:29extremely powerful, easy to test, easy to expand.
- 42:33It's really hard to go into detail without explaining the whole thing from the beginning.
- 42:36Sure.
- 42:37It's definitely worth checking out.
- 42:38It's actually online, fully published.
- 42:39If you search for it, I think you can actually find it on effectivepython.com because I'm so
- 42:44proud of that one.
- 42:44Yeah, nice.
- 42:44That's awesome.
- 42:45So you kind of pulled it out so everyone can get to it?
- 42:47Yeah, definitely.
- 42:47Cool.
- 42:48And then the final concurrency one that I thought was interesting was to consider concurrent
- 42:52dot futures for true CPU parallelism.
- 42:56Yeah, and this is the kind of hack that someone came up with.
- 42:59So there's this multiprocessing module that's built into Python now that will actually farm
- 43:04out work to sub-processes that are also Python.
- 43:08It's really ridiculous how it works, but for certain cases, it's extremely powerful, and
- 43:14it will actually speed up your program by the number of cores on your machine.
- 43:17It doesn't always work.
- 43:19It also breaks in a lot of weird ways, but when it does work, it's magical because you can go
- 43:25from something that was slow to something that's 10 times faster.
- 43:28So it's worth checking out, at least trying.
- 43:30I just wouldn't go too far.
- 43:31I think you just summed up multi-threaded parallel programming right there.
- 43:36It sometimes works, it sometimes breaks in weird ways, and when it works really well,
- 43:41it's magical, right?
- 43:42Yeah, it's true.
- 43:43Yeah, that's very true.
- 43:44I guess that's no exception.
- 43:45Yeah, but Python has its own peculiarities about how it breaks and how it works and whatever,
- 43:51right?
- 43:51That's a really good point.
- 43:52People forget to mention that, oh, Python only has one thread.
- 43:55It's like, that is a problem.
- 43:56It's a problem.
- 43:57But multiprocessing, multiprocess programming, multithreading in any other language was also
- 44:01really hard and error-prone, so let's not forget that.
- 44:04That's a great point.
- 44:05There was a group that was referring to the bugs that you get from multithreading as
- 44:11Heisen bugs, and I really like that way of thinking about it.
- 44:14Yeah, definitely.
- 44:15They're very hard to track down.
- 44:16So let's talk about just one more section in the book, and that was collaboration, like
- 44:22how you work well with other people and sort of like on teams and so on, right?
- 44:27Yeah, yeah.
- 44:28And I think Python is a huge community, like we were talking about before, and so working
- 44:31with others in Python is really important.
- 44:33Yeah, that's cool.
- 44:34And one of your pieces of guidance was to use packages rather than just patch around a bunch
- 44:39of files, right?
- 44:40Yeah.
- 44:41And this all depends on the size of your code base.
- 44:43You know, when you're starting out, it doesn't matter.
- 44:44Like until you have 10 files or something like that, it really doesn't matter.
- 44:48But you know, you should be willing to refactor your code into packages once you realize you
- 44:52have enough different working pieces, especially if you're working with different people.
- 44:57It's nice to split things a little earlier than you might have expected.
- 45:01So you give them room to grow.
- 45:02It's kind of like you'd buy, you know, if you have a kid, you buy them shoes a little, like
- 45:06one size a little bit bigger so that they can grow into them.
- 45:08Yeah.
- 45:09So packages are kind of like that.
- 45:10I think it's a good way to modularize your code base before it becomes too late.
- 45:15And I've been in code bases where it's been way too late.
- 45:17And we have files, six lines of Python code in them.
- 45:20And you're just like, why?
- 45:20How did this even happen?
- 45:22It's terrible.
- 45:24Yeah, I can imagine.
- 45:26Do you recommend having like an internal private package server?
- 45:29You know, it really depends on your company.
- 45:33I think if you're comfortable with pip, then yeah, it's pretty good, especially if you're
- 45:37doing deployments off of it.
- 45:38It can be really useful.
- 45:39If you have a security team that needs to vet things, it can be really valuable.
- 45:42Right.
- 45:44Maybe one team that builds the API and another team that builds the web part that consumes
- 45:48the API or something like that.
- 45:50Yeah, you can do stuff like that.
- 45:51I mean, it also depends on your source code repo.
- 45:53Google, we have just one giant repo for the entire company.
- 45:56So for us, I don't need a package server because I have the code.
- 45:58But yeah, it's good hygiene to have people publishing APIs that are stable and to think
- 46:04about things in that way.
- 46:05It's kind of the Netflix or Amazon approach to software engineering.
- 46:08And it works really well, more like a service-oriented architecture, but at the API level.
- 46:12Yeah, that's cool.
- 46:13So another piece of advice you had for collaboration was to consider the Reaper method for debugging
- 46:22output and helping people understand the state of your program.
- 46:26Yeah.
- 46:26Yeah.
- 46:27So yeah, Reaper Reaper print representation.
- 46:32I don't know why they call it that.
- 46:33I think it's pretty silly.
- 46:34But yeah, this is the most valuable tool for me in Python.
- 46:37Like, print is the first most valuable tool for me in Python.
- 46:40But the second most valuable tool besides print is Reaper.
- 46:43Because you can get detailed information about an object.
- 46:48And you can basically make an object that'll self-describe itself so that when you're debugging, you can
- 46:53print it out and say, hey, what's in this thing?
- 46:55What were the parameters that created this object?
- 46:56How did I even get here?
- 46:57Reaper and under-under-repper is a really great way to do that.
- 47:01And Python has built-in support for it all over the place.
- 47:03So it's definitely worth checking out if you don't use it.
- 47:05Right.
- 47:05Absolutely.
- 47:06If you just take a list and print it, you'll get that representation for all the items it
- 47:11contains.
- 47:11That's right.
- 47:12And it basically evaluates back to the Python statement that it would have taken to create the
- 47:16same list.
- 47:17And so you usually can copy and paste reppers back into an interpreter to test them out.
- 47:22So it's a really nice way to do kind of an interactive debugging session with your own code.
- 47:26That's cool.
- 47:27And the final collaboration thing that I actually hadn't heard of was you can understand memory
- 47:32allocations and leaks with something called trace malloc.
- 47:35Yeah.
- 47:37And this is another Python 3 only thing.
- 47:39And it's wonderful.
- 47:44Because if you've ever had memory leaks in Python, for especially long-running processes,
- 47:47it's really hard to track down where your memory usage is going.
- 47:51Any project of size that I've been on, we run a lot of servers at Google, so we have this
- 47:56a lot.
- 47:56You end up having this problem where you look at your garbage collection or your heap, and
- 48:00it just keeps growing.
- 48:03You're like, where's the actual space going?
- 48:05And the tools to do that in Python are horrible.
- 48:07Python 2.7 and before, they're all bad.
- 48:10And trace malloc, they finally fixed this in Python 3.
- 48:13And yeah, it basically will tell you exactly like, this is the object you have too many of.
- 48:18This is exactly where it was allocated.
- 48:19Here are the parameters that were used at the time.
- 48:22And so now it's like, orders of magnitude easier to figure it out, which is really great.
- 48:26There is a port of that code to Python 2.7, I believe.
- 48:31But I don't know how well-maintained it is.
- 48:33And I don't think it's actually, it has to actually modify the CPython run, like binary
- 48:38itself.
- 48:38It can't be done as a C extension module.
- 48:40So I think it'll never be added to Python 2, which is unfortunate.
- 48:44Right.
- 48:45So you might have to like build your own version of the source code with that baked in and then
- 48:49run your code on that.
- 48:50Which is pretty scary, but it might be worth it.
- 48:53Yeah, maybe not for use in production too much.
- 48:55Yeah, I wouldn't use in production.
- 48:56For sure.
- 48:58Okay.
- 48:59So those are a bunch of really awesome things that I think will help, you know, pretty
- 49:04much people of all level.
- 49:05Thanks, man.
- 49:06Yeah.
- 49:07How long has the book been out?
- 49:09It's been out since April, basically.
- 49:12And it's doing pretty well.
- 49:15And this week we also have a video that's coming out, which is a lot of the same content, but
- 49:20in me just typing out the actual code format.
- 49:23So some people who learn better from seeing demonstrations, it might be better for them.
- 49:29But yeah, it's had a lot of good feedback, a lot of good reviews on Amazon and other places.
- 49:34A lot of bugs reported of things I did wrong, but not too many bugs.
- 49:38There's only one bug so far that I'm really embarrassed about where I did a multiply instead
- 49:43of divide, but the rest of them are all pretty good.
- 49:46Well, the multiply, divide, what's the difference?
- 49:50Yeah.
- 49:50You know, I just, I got confused.
- 49:52Math is hard.
- 49:57So people can go get it on Amazon and I'll definitely link to the book, but you have
- 50:03a book code that we can give to listeners so they can get a bit of a discount, right?
- 50:07Yeah.
- 50:07And it's, it's the code is, FPI, E F F P Y. And the simplest way to use
- 50:12it is you go to inform it.com like I N F O R M I T.com slash F PI, all caps E F F P Y.
- 50:21And, that, that lets you buy the book directly from the publisher.
- 50:23And for some places, that are not in the United States also, it can be cheaper
- 50:28this way than going through Amazon.
- 50:29and it's a, it gives a discount off the ebook version, the physical book, and then also
- 50:35this new video that just came out this week.
- 50:36you can get them all there.
- 50:38Yeah.
- 50:38You just released that.
- 50:39You, released this, this nice new video training version of the book.
- 50:43So, I'll be sure to link to that as well.
- 50:45That'd be cool.
- 50:45Yeah.
- 50:46Thank you.
- 50:46Yeah.
- 50:47You bet.
- 50:48So Brett, anything else you want to give a shout out to or let people know about that
- 50:52we somehow didn't touch on?
- 50:53the only other thing is, yeah, like the book websites, effective python.com and,
- 50:58uh, everything you want to know about me, you can find there, and, please report
- 51:03any bugs you have.
- 51:04Those are on, on GitHub with all the example code.
- 51:06And I'm trying to make sure that, anything that's wrong, I address in there.
- 51:10but yeah, if you have questions, there's also a link to
- 51:13email me directly.
- 51:13So if you, if you hit an issue, I'd love to hear from you.
- 51:16I'm happy to answer your question.
- 51:18Excellent.
- 51:19So two final questions before I let you go.
- 51:21What is your current favorite code editor?
- 51:24If you're going to sit down and write some Python, what do you, what do you open up?
- 51:26I, I am a sublime fan.
- 51:28I use text mate for a long time.
- 51:29I still use Emacs, when I'm on a, on a terminal.
- 51:32So I use Emacs every day also.
- 51:34I don't use VI, but I can use less so I can, I can do the read part of it, I guess.
- 51:39and, but yeah, sublime is my favorite, editor.
- 51:43Nice.
- 51:44And then of all the 60,000 plus, whatever it is, PyPI packages, what, what ones do you
- 51:52think people should know about that?
- 51:53Maybe they don't know.
- 51:53NumPy, obviously, I guess that's, everyone knows about that one.
- 51:58SQLAlchemy is an amazing tool, especially the relational package, for doing, database
- 52:04lookups.
- 52:04flask is a great web framework that I like a lot.
- 52:07and then there's a bunch of stuff around, speeding up programs that I'm, I'm trying
- 52:13to get more into.
- 52:13Theano is one and Numba is another.
- 52:16These are things that let you use your GPU through Python, which is super cool.
- 52:20And you can use that for things like neural network training and machine learning and stuff
- 52:23I haven't really spent enough time doing.
- 52:24So I think I'm really excited to try out some more of these computational tools and Python
- 52:28packages.
- 52:29Yeah, that's really awesome.
- 52:30If you, you know, people who've looked at it, they know, but if you've not looked at
- 52:35the parallel capabilities of GPUs, it's like, it's astounding, right?
- 52:39It's crazy.
- 52:40And the fact that you can like use that in three lines of Python is crazy.
- 52:43So I think it's just speaks to the community that Python has of scientists and, and, you
- 52:48know, it's just such a, such a diverse community.
- 52:49So it's really great to see these packages, blossoming in Python before many other languages.
- 52:54Yeah, absolutely.
- 52:55Brett, it's been a very interesting conversation.
- 52:58I appreciate it.
- 52:59Yeah.
- 53:00Thanks a lot for having me on and asking all those great questions.
- 53:02Yeah.
- 53:02And I love the book and I encourage the readers to go check it out and they'll enjoy it.
- 53:07Thanks very much.
- 53:08Yeah.
- 53:08Talk to you later.
- 53:09All right.
- 53:10See ya.
- 53:10This has been another episode of talk Python to me.
- 53:14Today's guest was Brett Slacken.
- 53:16And this episode has been sponsored by hired and code chip.
- 53:19Thank you guys for supporting the show.
- 53:21Hired wants to help you find your next big thing.
- 53:23Visit hired.com slash talk Python to me to get five or more offers with salary.
- 53:28And equity presented right up front and a special listener signing bonus of $4,000.
- 53:32Code chip wants you to always keep shipping.
- 53:36Check them out at code chip.com and thank them on Twitter via at code chip.
- 53:40Don't forget about the discount code for listeners.
- 53:42It's easy.
- 53:43Talk Python, all caps, no spaces.
- 53:46You can find the links from the show on talkpython.fm/episodes slash show slash 25.
- 53:52While you're there, be sure to subscribe to the show.
- 53:55Open your favorite podcatcher and search for Python.
- 53:57We should be right at the top.
- 53:58You can also find the iTunes and direct RSS feeds in the footer of the website.
- 54:03Our theme music is Developers, Developers, Developers by Corey Smith, who goes by Smix.
- 54:08You can hear the entire song at talkpython.fm/home slash music.
- 54:12This is your host, Michael Kennedy.
- 54:15Thanks for listening.
- 54:16Smix, take us out of here.
- 54:21Chilled in, haven't been sleeping.
- 54:23I've been using lots of rest.
- 54:25I'll pass the mic back to who rocked it best.
- 54:28Developers, developers, developers.
- 54:31Developers, developers, developers.
- 54:38developers.
- 54:38you
- 54:39you