Latest / Talk Python To Me / #332: Robust Python
Transcript
- 0:00Does it seem like your Python projects are getting bigger and bigger?
- 0:02Are you feeling the pain as your code base expands and gets tougher to debug and maintain?
- 0:07Patrick Viafor is here to help us write more maintainable, longer-lived, and more enjoyable
- 0:12Python code.
- 0:13This is Talk Python To Me, episode 332, recorded August 30th, 2021.
- 0:19Welcome to Talk Python To Me, a weekly podcast on Python.
- 0:35This is your host, Michael Kennedy.
- 0:37Follow me on Twitter, where I'm @mkennedy, and keep up with the show and listen to past
- 0:41episodes at talkpython.fm.
- 0:43And follow the show on Twitter via at Talk Python.
- 0:46We've started streaming most of our episodes live on YouTube.
- 0:50Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming
- 0:55shows and be part of that episode.
- 0:57This episode is brought to you by Clubhouse, soon to be known as Shortcut, by masterworks.io,
- 1:03and the transcripts are brought to you by assembly.ai.
- 1:07Please check out what they're offering during their segments.
- 1:09It really helps support the show.
- 1:10Pat, welcome to Talk Python To Me.
- 1:13Thank you.
- 1:14I'm so honored to be here.
- 1:15Long-time listener.
- 1:16Oh, that's fantastic.
- 1:17I really, really appreciate that.
- 1:18It's an honor to have you here.
- 1:20We're talking about one of these subjects that I really enjoy.
- 1:24I feel like it's one of these more evergreen type of topics.
- 1:28You know, it's super fun to talk about the new features in Flask 2.0, but that's only relevant
- 1:34for so long and for so many people.
- 1:35But writing software that's reliable, that can be changed over time, doing so in a Pythonic
- 1:41way, that's good stuff to learn no matter where you are in your career.
- 1:45Oh, I absolutely agree.
- 1:47You've written a book called Robust Python, which caught my interest.
- 1:51I, as you can imagine, get a couple of books and ideas said to me periodically per day.
- 1:57And so they don't usually appeal to me.
- 2:00But this one really does for the reasons that I exactly stated in the opening.
- 2:04And we're just going to sort of riff on this more broad idea of what is robust Python?
- 2:09What is clean code?
- 2:11Like, how do you do this in Python and make it maintainable for both you in the future
- 2:15and other people and so on?
- 2:16Yeah, sounds good.
- 2:17Before we get to that, though, let's start with you.
- 2:20What's your story?
- 2:21So I got into programming like many males my age.
- 2:25I loved video games as a kid.
- 2:26And I was 12 or 13.
- 2:29And some ad in one of my video game magazines caught my eye for video game creator studio.
- 2:34Oh, nice.
- 2:35And it was this C++, just C++ engine, but it provided easy ways to do sprites and animations
- 2:42and particle effects.
- 2:43And they gave you step-by-step instructions.
- 2:46Here's how you build Pong.
- 2:47Here's how you build Frogger.
- 2:49And here are the assets.
- 2:50I started riffing on it.
- 2:51I really came to love it.
- 2:52I then took a programming class in high school, True Basic, which I don't remember much of other
- 2:59than I don't think I'd ever go back to it now.
- 3:01But it interested me enough that I decided to go to computer science college.
- 3:06I learned more about the video game industry, especially some of the hours they work and said,
- 3:10you know what, maybe the video game industry is not for me, but I still loved programming
- 3:15at its heart.
- 3:15So I continued on and just found a few jobs after college and just went from there.
- 3:20As far as Python went, I worked in telecom for a little bit.
- 3:24And early 2010s, we had some test software.
- 3:27It was all written in the Tickle programming language.
- 3:30And that is an interesting programming language.
- 3:33As far as types go, everything's treated as a string.
- 3:36And it led to some very unmaintainable code.
- 3:39So a few sharp engineers and myself, we decided, you know, what would it look like if we wrote
- 3:43this in Python?
- 3:43And a whole test of the automation was born from there.
- 3:46And we just went, wow, Python makes everything nicer.
- 3:50Like, this is so much pleasurable to work with.
- 3:52And I've done like C++ and Java before then.
- 3:55So Python was this breath of fresh air.
- 3:57And I just fell in love with the language.
- 3:59Yeah.
- 3:59Those are both very syntax symbol heavy languages.
- 4:03I've done a ton of C++.
- 4:05I did professional C++ development for a while.
- 4:07I have never done much Java.
- 4:09But yeah, they're really interesting.
- 4:12I remember when I came to Python, I came from C#, but also from C++.
- 4:16And just in my mind, those symbols, all the parentheses on the if statements and the semicolons
- 4:23at the end of the line and all that business, it was just required.
- 4:26That's just what language is needed to be.
- 4:28And then they weren't there.
- 4:30And I'm like, I just, I'm having a hard time with this.
- 4:32Right.
- 4:33And I felt it was weird.
- 4:34But then when I went back just to work on like a project that was still ongoing, it seemed
- 4:39more weird.
- 4:39I'm like, wait a minute.
- 4:40My eye, you know, like the wool has been taken off my eyes.
- 4:43I know now these are not required and still here I am continuing to write them.
- 4:48And it just drove me crazy once I realized I don't have to put these things here.
- 4:52It's just this language that makes me.
- 4:53And so, yeah, it was really nice.
- 4:55Yeah.
- 4:55Yeah.
- 4:56Python kind of captured that magic for me.
- 4:58And it's funny because going back to C++ every once in a while, my C++ got a lot better
- 5:04because of Python.
- 5:04You start focusing on the simple.
- 5:06That's nice.
- 5:07Yeah.
- 5:07Yeah, exactly.
- 5:08You're not trying to flex with your double pointers and all that kind of stuff.
- 5:11It's like, we don't need this.
- 5:13Let's not do this.
- 5:14Come on.
- 5:14Very cool.
- 5:15So how about now?
- 5:15What are you doing?
- 5:16So right now I am a software engineer at Canonical.
- 5:18I'm on their public cloud team.
- 5:20So we're building the Ubuntu operating system for public clouds, AWS, Azure, GCE, a couple others.
- 5:27And so we customize the images for clouds, work with a lot of other canonical teams to make sure that their changes are reflected in our software.
- 5:36We maintain the CI/CD pipelines to deliver those as often as we can.
- 5:41Most of the toolings are in Python, so I get to use Python day to day, which makes me happy.
- 5:45Oh, that's really cool.
- 5:46What kind of features are we talking about here?
- 5:49Or aspects?
- 5:50Yeah, general hardware enablement.
- 5:52Clouds may have new instances, new processor types.
- 5:56Working to make sure that that's enabled.
- 5:58Do a lot of close work with our kernel team.
- 6:02Features that the cloud themselves might request.
- 6:05Maybe, you know.
- 6:06Like something the cloud needs to set up and maintain the VM aspect.
- 6:10Yeah.
- 6:11Okay.
- 6:11More on the infrastructure side.
- 6:13Maybe how do they hibernate their VMs?
- 6:16Okay.
- 6:16How do they improve boot speed?
- 6:18Those sort of changes.
- 6:19Yeah.
- 6:19Or how do they improve the security profile?
- 6:21That's something I'm working on right now with some of our clouds.
- 6:23Yeah.
- 6:24Super, super important.
- 6:25Yeah.
- 6:26That's part of the promise to go into the cloud is often there's better security and better durability.
- 6:31But if it fails, it fails for potentially all of some big chunk of the internet, right?
- 6:36Like that's the consequence of failure is also higher.
- 6:39So.
- 6:39Yeah.
- 6:39Yeah.
- 6:39You have to be very aware of how many people are using your software when you deploy to the cloud.
- 6:44Does it make you nervous to work on that kind of stuff?
- 6:46Oh, absolutely.
- 6:48Yeah.
- 6:48I wouldn't, I'd be lying if I said it didn't, but you, you learn to be careful.
- 6:52You learn to really focus on making everyone, you know, having good communication between your teams, making sure there's no surprises for anyone, that sort of thing.
- 7:01I remember that as well, just working on certain things.
- 7:04Like the first e-commerce system I wrote, I'm like, this thing's going to be charging thousands of dollars per transaction.
- 7:09And I might screw this up.
- 7:11And I'm really worried for deploying it for the whole company.
- 7:14There's like big purchases people were doing.
- 7:16And it made me really nervous.
- 7:18But at the same time, one of the things I've come to learn over my career programming is it's one of the things that will really put a sad, sad look on your face is if you spend a lot of time and create beautiful software and no one uses it.
- 7:30That's right.
- 7:31Yeah.
- 7:32So the, even though it may be stressful that it's getting used a lot and it's really central, that's also amazing, right?
- 7:37Yeah.
- 7:37But it's also made me a better programmer because you just start thinking about explicit error cases more.
- 7:42And my last job, I mentioned I did telecom and 911 calls get routed through your equipment.
- 7:47You don't want to fail that.
- 7:49And yeah.
- 7:50Wow.
- 7:51It is scary at first, but you learn to develop disciplines over time of, okay, how do we make sure we're not making mistakes?
- 7:57You know, speaking of that, I think that's maybe a good segue in to talk about this idea of robust Python.
- 8:04First of all, like, let's just talk about your book for just a minute and then we'll just get into the general idea of it.
- 8:08Like what motivated you to write this book?
- 8:11So I mentioned I've done C++ development in the past.
- 8:13I started diving heavy into modern C++ and how it uses a lot more type safety features and some earlier versions of C++.
- 8:23Did a quick dabble into Haskell just from a learning perspective and really started to love static types.
- 8:29But my day-to-day language was Python.
- 8:31So I really, really dove deep on, you know, how do I make my Python safer moving forward?
- 8:36So I pitched to a few publishers.
- 8:38I want to write a book about, you know, type system best practices in Python.
- 8:42Let's talk type checkers.
- 8:43Let's talk about design types and so on and so forth.
- 8:46O'Reilly, who published my book, they bit and they said, oh, that sounds interesting.
- 8:51Can we expand the scope a little bit more?
- 8:53And I thought, okay, well, why do I write types in Python?
- 8:56Why do I, you know, advocate type systems?
- 8:59It's to make things more maintainable, make things live longer, to make things clearer.
- 9:04And the idea of robust Python came out of that.
- 9:06Well, I think it's really a pretty interesting idea.
- 9:09I do think when you come from these languages like C++ or Java or something, there is something to be said for it literally is verified to be clicked together.
- 9:21Just like a perfect jigsaw puzzle.
- 9:23Yeah.
- 9:23Right.
- 9:23It won't catch every error, but it can catch more errors.
- 9:27And that's a good thing.
- 9:28Yeah.
- 9:28Well, I remember how excited I was when I got my first non-trivial C++ thing to compile.
- 9:33And I'm like, yes, I've done it.
- 9:35Little did I know, like I was in for it.
- 9:37I mean, it was out of compiler errors and into like real errors.
- 9:41Yeah.
- 9:41At that point.
- 9:42Right.
- 9:42Yeah.
- 9:43The fun errors.
- 9:44Right.
- 9:45Yeah.
- 9:45Exactly.
- 9:46The why, what is it?
- 9:47What is it?
- 9:48Seg fault?
- 9:49Whatever.
- 9:49I don't know.
- 9:51We're going to work on that.
- 9:52So anyway, that was, that was really interesting.
- 9:55I, I do think that it's not required, right?
- 9:59I do think that there is really interesting code being written in Python.
- 10:02And you can see that how it's, it's being adopted in all these ways.
- 10:06The biggest, maybe example I have in mind of these two things side by side is, you know,
- 10:11YouTube versus Google video and how Google video was in Python with 20 engineers.
- 10:16Google video was a hundred C++ engineers.
- 10:19And eventually Google just said, all right, we're going to put that project aside and buy
- 10:22YouTube because they just keep out running us in features.
- 10:25Yeah.
- 10:25I think that's the beauty of Python is that you can build things fast.
- 10:29You can see them working faster.
- 10:31And you don't have to fight the compiler as much of the way.
- 10:34So it's almost like these two things are at odds.
- 10:36And the answer is just Python's gradual typing.
- 10:38You just type as you need to.
- 10:40You add typing where it makes sense.
- 10:42And I won't be prescriptive and say you need types everywhere, but there are certain places
- 10:47where it makes a lot of sense and save you money and time.
- 10:49I do find it pretty interesting how they've implemented types in Python.
- 10:53And to be clear, this idea of robust Python that you're focused on, types is just one part
- 10:58of it, but it sounds like it was the genesis of it.
- 11:00It was absolutely the genesis.
- 11:02Yeah.
- 11:02Yeah.
- 11:03So we have sort of two other realities that we might look at.
- 11:08We could look at C++ or C# or Java.
- 11:10They're all the same in that regard.
- 11:12They're like static compiled languages.
- 11:14And then we've got something that's much closer to Python with TypeScript, where they said,
- 11:19we have the same problem.
- 11:20We have JavaScript, which is even less typed because the runtime types are all just weird
- 11:26dictionary prototype things anyway.
- 11:28And we want to make that reliable for larger scale software and integrations and stuff.
- 11:33So we create TypeScript.
- 11:34But the real fork in the road, I think that was interesting is the TypeScript people said,
- 11:39we're going to apply the ideas of absolute strict typing.
- 11:43Once you start down that path, it's all down that path.
- 11:46And they have to match up.
- 11:47Whereas in Python, it's like, let's help you down this path, but not give up the zen of Python,
- 11:54where you can easily put things together and you're not restricted by this type system.
- 11:59But if you run the right tools, be that PyCharm, VS Code, or mypy or something like that,
- 12:05it'll be there to help you make it better in lots of ways.
- 12:08Oh, absolutely.
- 12:09I think that's a really creative and interesting aspect of it.
- 12:12Yeah.
- 12:12Yeah.
- 12:13I absolutely agree with that.
- 12:15A lot of things that I discuss throughout the book is the idea that these are tools in your toolbox.
- 12:22And so I talk about types.
- 12:24I talk about API design.
- 12:25I talk about sensibility.
- 12:26They're all tools and they shouldn't be applied everywhere.
- 12:30I really want to start focusing on first principles.
- 12:33Why do we do the things we do in software engineering?
- 12:35And what are the most appropriate for them?
- 12:38You had a really interesting quote in your book about software engineering.
- 12:42And I've always sort of struggled to have this conversation with people like, oh, are you a programmer?
- 12:48Are you a coder?
- 12:49Are you an engineer?
- 12:50Like, where are you on that?
- 12:52Like, is that even a meaningful distinction?
- 12:54And to a large degree, I've always felt like it was just sort of whatever sort of culture you're in.
- 12:59You know, if you're in a startup, it's one thing.
- 13:01If you're in like a giant enterprise, they may value a different title in a different way.
- 13:05It's all kind of the same.
- 13:06But you had this cool quote that said something like software engineering is programming integrated over time.
- 13:11Yes.
- 13:12And I wish I could claim credit for that, but that actually came from Titus Winters of Google and C++ Con or CPP Con Talk.
- 13:19And it's just really resonated with me.
- 13:22We program, but software engineering is the efforts of that programming over years or decades.
- 13:29Your code will live decades.
- 13:31The more valuable it is, the longer live it probably will be.
- 13:34I've worked on code that's been 15 years old when I started on it.
- 13:38And there's code that I wrote 12 years ago that's still running operationally.
- 13:42And that scares me to some degree.
- 13:44Because like, oh, did I know what I was doing back then?
- 13:48But it just reemphasized like why it's so important to think towards the future of what your audience.
- 13:55You're going to have maintainers that come after you.
- 13:57And do you want them to curse your name?
- 14:00Or do you want them to be like, oh, thank goodness, this person wrote something that I can use.
- 14:03It's really easy.
- 14:04And I always prefer the latter on that.
- 14:06I also like to say.
- 14:08And the nicer code that you write and the more durable and long live code that you write,
- 14:13the more it can continue to have a life even after you've stepped away from the project, right?
- 14:19It's like, this thing is still working well.
- 14:22We can keep growing it rather than it's turned into a complete pile of junk that we've got to
- 14:26throw away and start over, right?
- 14:27So that's a goal that you might want.
- 14:29And then also that long-term maintainer might be you.
- 14:32Yep.
- 14:32Yep.
- 14:33You might be working out five years from now and you go, why did I make the decisions that I did?
- 14:37I don't remember this.
- 14:38Maybe you've jumped to a different project and came back.
- 14:41It absolutely can be you.
- 14:44This portion of Talk Python To Me is brought to you by Clubhouse.io.
- 14:48Happy with your project management tool?
- 14:50Most tools are either too simple for a growing engineering team to manage everything or way
- 14:55too complex for anyone to want to use them without constant prodding.
- 14:58Clubhouse.io, which soon will be changing their name to Shortcut, is different though, because
- 15:03it's worse.
- 15:03No, wait.
- 15:04No, I mean, it's better.
- 15:05Clubhouse is project management built specifically for software teams.
- 15:09It's fast, intuitive, flexible, powerful, and many other nice positive adjectives.
- 15:13Key features include team-based workflows.
- 15:16Individual teams can use Clubhouse's default workflows or customize them to match the way
- 15:21they work.
- 15:22Org-wide goals and roadmaps.
- 15:24The work in these workflows is automatically tied into larger company goals.
- 15:28It takes one click to move from a roadmap to a team's work to individual updates and back.
- 15:33Type version control integration.
- 15:35Whether you use GitHub, GitLab, or Bitbucket, Clubhouse ties directly into them so you can
- 15:40update progress from the command line.
- 15:42Keyboard-friendly interface.
- 15:44The rest of Clubhouse is just as friendly as their power bar, allowing you to do virtually
- 15:49anything without touching your mouse.
- 15:51Throw that thing in the trash.
- 15:52Iteration planning.
- 15:54Set weekly priorities and then let Clubhouse run the schedule for you with accompanying burndown
- 15:59charts and other reporting.
- 16:00So give it a try over at talkpython.fm/clubhouse.
- 16:05Again, that's talkpython.fm/clubhouse.
- 16:08Choose Clubhouse.
- 16:09Again, soon to be known as Shortcut, because you shouldn't have to project manage your project
- 16:14management.
- 16:17Let's talk about some of the core ideas that you have about making software maintainable,
- 16:23reliable.
- 16:24One of the things you talk about is the separation of time and how code has to communicate or the
- 16:30artifacts that we all produce around code has to communicate with people both maybe almost
- 16:37immediately.
- 16:37Right?
- 16:38Like, I'm working on this project with a couple of other developers and we need to,
- 16:42like, keep it going forward.
- 16:43The other one is, like, way down in the future, someone comes back and they're like, oh, I'm
- 16:47new here.
- 16:48The person who created it left.
- 16:49Maybe talk about some of those ideas that you've covered.
- 16:52Yeah.
- 16:53And so it feels a little weird because what we're talking about is asynchronous communication.
- 16:57And it's weird to talk about that on a Python podcast and not talk about async away.
- 17:01Yeah, exactly.
- 17:02But it's asynchronous communication in real life, which I actually think is much harder.
- 17:06You have to think about your time traveling to some degree.
- 17:09You have to think about the future and you have to communicate to them.
- 17:12You probably will never meet them.
- 17:13You'll never talk to them.
- 17:15The only thing that lives on are the artifacts you create.
- 17:17So your code, your documentation, your commit messages, that's what people in the future are
- 17:23going to construct this mental model of your work from.
- 17:25They're going to be doing archaeology when things go wrong.
- 17:27Why is this code the way it is?
- 17:29Is it safe to change?
- 17:31What were the original intentions?
- 17:33And so the more you can embed that into code you write and the surrounding commit messages,
- 17:37documentation, the more robust your code base is going to be, the more you're communicating
- 17:43intent future.
- 17:44That's one of the things that was so important for 2020, 2021 for all of us, right?
- 17:49Like, yeah, we didn't know how much we were going to need it because there's always been
- 17:53this kind of tension.
- 17:54Well, there's the open source world and these other projects.
- 17:58And there's those weird remote teams, but we come to our cubicles and we all sit down
- 18:02and we have our stand up in the morning and we write our software together.
- 18:05And like that's, and we use, you know, Perforce or something internal where we lock the file.
- 18:11No one else can edit the file till I unlock the file, right?
- 18:13Like there's these, these different ways.
- 18:15And we've been moving more and more towards this sort of everything.
- 18:19Even if the person is right next to you, the way we work is as if they were across the
- 18:23world.
- 18:23Yeah.
- 18:24And, you know, it's, it's been really, I guess, lucky for us as an industry that that
- 18:28was mostly in place.
- 18:30Yes, absolutely.
- 18:31That actually became true.
- 18:32Yep.
- 18:32And so I think you touched on an interesting point of a lot of developers think, oh, if
- 18:38we're close in space, we can collaborate.
- 18:40You know, I don't have to worry about my remote teams and I don't have to worry about, you
- 18:44know, someone global.
- 18:46But by thinking of that, your collaboration in that terms, it sets you up to think about
- 18:51the future as well, because you could be asynchronous in space or asynchronous time.
- 18:55Right.
- 18:56And basically the same tools are there to, to address it.
- 19:00The same strategies help with both.
- 19:01Yeah.
- 19:02So one of the things that you talked about was this principle of least surprise.
- 19:08Yeah.
- 19:09Tell us about that principle.
- 19:10Yeah.
- 19:11The principle of least surprise also known as the principle of least astonishment.
- 19:13I feel like it's safe to say most developers have gone through a code base and been legitimately
- 19:19surprised and went, that function does that?
- 19:22Oh my goodness.
- 19:23I would never have thought that.
- 19:24Once worked on a nasty bug where the get event function was setting an event.
- 19:30And I kept overlooking it because I'm like, what's a get event?
- 19:33It's just a getter.
- 19:34I can ignore this.
- 19:35And like two days later.
- 19:36This will have no side effects.
- 19:37This will be fine.
- 19:38Two days later.
- 19:38I'm like, let me go step through this.
- 19:40And I was floored.
- 19:41I'm like, of course this explains my bug.
- 19:43So your goal when developing software is you don't want to surprise your future readers.
- 19:48I mean, I think this is why people say avoid clever code, favor clear code over clever code.
- 19:53You don't want to surprise readers.
- 19:56Many, many people may not be as well versed in the languages.
- 20:00Maybe they're coming from a different language, maybe from TypeScript to Python.
- 20:03The more you rely on clever tricks or poor naming or just the wrong patterns, you're throwing people off for a pee and they need.
- 20:11There's an added cognitive burden that they must then carry to understand what you've read.
- 20:16One of the beautiful things about different abstractions are here's a function.
- 20:20I read the function name.
- 20:21That's all I need to know.
- 20:22Here's a class.
- 20:24I understand what the class does.
- 20:25I don't need to go and look into the details.
- 20:28And it lets you build these more larger building blocks of conceptual models.
- 20:33But if that's not true, right?
- 20:35Like if a getter is a setter, well, then all of a sudden those things are all out the window and that's bad.
- 20:40Yeah.
- 20:41I mean, we work by building mental models and you need trust to build those mental models.
- 20:45And as soon as that trust is violated, it just starts taking time to do everyday tasks.
- 20:50You say, I want to implement a single API endpoint.
- 20:54Well, if I have to go dig through 10 different files just to make sure I'm doing everything right, that's going to slow me down.
- 21:00If I can trust that my mental model is correct and that it's been shown to be correct time and time again, I can put more faith in that code and I can feel safer to start changing.
- 21:09Yeah, for sure.
- 21:10Another thing that I really liked about some of your ideas was that you talked about people having good intentions, even if they write bad code.
- 21:19Like they're trying their best and they're for the most part.
- 21:22I mean, there might be people who are just lazy or whatever, but for the most part, like they tried to write this well.
- 21:27Even if it came out bad, they probably tried to write it well and it just didn't turn out as good as they hoped.
- 21:32Or even they wrote it well and it's just changed over time and those original assumptions got lost.
- 21:38Right, right.
- 21:38It made sense in the early days and the assumptions or the context changed.
- 21:42Now it's no longer accurate.
- 21:44Yeah.
- 21:44Or it's inflexible and it's really hard to use to extend to your current use case.
- 21:49I see that all the time.
- 21:50One of the ideas that I thought was interesting is this idea of legacy code.
- 21:54And I've always been kind of fascinated with what does legacy code mean?
- 21:57Yeah.
- 21:57Because legacy code for one person could be COBOL.
- 22:01Legacy code for another person could be Python 2.6.
- 22:05That's pretty old.
- 22:06It could even just be Python 3.6 that's been around for a while, right?
- 22:12And there's different people who have different definitions.
- 22:14Michael Feathers has a cool book called Working Effectively or Effectively Working with Legacy Code.
- 22:18Something like that.
- 22:19That's an interesting book.
- 22:20I believe it comes from maybe a slightly different time, but still some of the ideas will make you think.
- 22:25And I was going to quote that book actually because his is a legacy code base is a code base that doesn't have tests.
- 22:30And I used to think that for a long time.
- 22:33I love tests, but I've come to evolve my understanding of legacy code.
- 22:39And here's where the definition I've settled on.
- 22:41It's a legacy code, a legacy code base.
- 22:43It's a code base in which you can no longer communicate to the original authors or maintains.
- 22:47So the length of time doesn't matter as much.
- 22:50If you've lost contact from the original authors, all you have is the code base and its surrounding documentation to understand why it's doing the things it does.
- 22:59So that's become my favorite definition for legacy code as a place.
- 23:02Yeah, I like that one too.
- 23:03I don't really like the tests one.
- 23:05I see where it comes from, but I feel like it's judging a world from too strict of a place.
- 23:13Because not every piece of code is written in a way that it has to be absolutely correct.
- 23:20Yeah.
- 23:21Right.
- 23:21So I think this is also a good way to sort of scope this conversation.
- 23:26Because a lot of times people hear, oh, I have to use protocols and I have to use mypy and I have to use X, Y, and Z.
- 23:34And I have to do all these fancy things because Pat and Michael said so because they were awesome.
- 23:38And it's a big hassle.
- 23:39I don't think I need it.
- 23:40But here I'm trying to be a good software developer, right?
- 23:43So I'll give you an example.
- 23:45Years ago, I switched all the Talk Python stuff, especially the Talk Python training stuff, from relational databases and SQLAlchemy over to MongoDB and MongoEngine.
- 23:55And so I had to write a whole ton of code that would take a couple of tables and then put them into a structure and then put them in Mongo.
- 24:02And that was all fine and good.
- 24:04But here's the thing.
- 24:05The moment that code ran successfully, I never wanted to run it again.
- 24:09It only had to run once.
- 24:10It had to move the data one time.
- 24:12When it was done, there was no scenario where I cared about its typing or I cared about its continuous integration.
- 24:18I could have deleted it.
- 24:20I just kept it because, hey, source control.
- 24:21But there's these scenarios, right?
- 24:24On the other hand, you talk about if you're an online reservation system, like the reservation booking engine, that part needs an entirely different bit of attention and mindset than my little migration script, right?
- 24:38Yeah.
- 24:38And what I see is what value are the things delivering?
- 24:42Some things have one-off value, and that's perfectly okay.
- 24:45Your migration script, it's service value, but there won't be much value derived from it in the future.
- 24:51Maybe from an archaeology standpoint of how did I go do this?
- 24:54Yes, exactly.
- 24:56Maybe.
- 24:56With something that's core to a business, a reservation booking engine, it delivers value when you built it, but you want it to keep delivering value throughout its lifetime.
- 25:07And furthermore, the people who are working on it want to deliver value just as fast as you did in the beginning.
- 25:12So you don't want to slow down the future.
- 25:15You start getting into where you get product managers saying, why is this taking so long?
- 25:19This is super easy.
- 25:21Why do you have to spend three weeks just adding this one little field?
- 25:24And the answer is often, oh, you know, we didn't think about how to enable value faster when we built it.
- 25:31And there's a tricky line there because you can't just go play everything and say, I'm going to make everything super flexible.
- 25:36That often has the reverse effect.
- 25:38It makes things too flexible and that becomes unmaintainable.
- 25:41But there's a fine line between saying, okay, I'm going to think for the future and deliver value now.
- 25:46Yeah.
- 25:46If every dependency can be replaced and everything can be configured from a file, some settings file and like you never, you know, eventually that becomes a nightmare.
- 25:55It sounds cool.
- 25:56It's not cool.
- 25:57I worked on some of those.
- 25:58Yeah.
- 25:59It's just painful.
- 26:00And so here's the advice I give to people who want to think about how to make their code base more maintainable.
- 26:05Target your moneymakers, the things that produce value, because those are the things you want to protect.
- 26:09And whatever value means to you.
- 26:11Target things with high churn.
- 26:13So you can look in your Git history.
- 26:15You can see what files change the most.
- 26:16Chances are those are the files that are being read the most.
- 26:19They're the files that people are working in the most.
- 26:21Putting more safeguards in those files, making them more extensible will pay off just because more people are using them.
- 26:28Look for areas where you do large swaths of changes.
- 26:32It's called shotgun surgery, where if you want to add a single thing, you have to touch 20 files.
- 26:37The same 20 files keep getting changed again and again in a grouping.
- 26:41That tells you that, you know, if I were someone coming in new to the project, how do I know it's 20 and not 19, 21?
- 26:47That's a place we can simplify.
- 26:48Those are the things that are super easy to forget a case.
- 26:52Oh, yeah.
- 26:52Like, oh, we added this feature and every if statement had an else if that covered the new thing, except for that one where we did the auditing or except for that one where we checked if they were an admin.
- 27:03Oh, that one.
- 27:04Now everyone's an admin.
- 27:05Whoops.
- 27:06Yep.
- 27:06And so that's the sort of places where I think type hinting is and other strategies are super useful because you can start encoding that those ideas of I want to catch this when I miss a case.
- 27:18You can start encoding that into your checks, into linters, type checkers, static analysis, and so on and so forth.
- 27:25Important.
- 27:25I think people are pretty familiar with the typing system these days.
- 27:31I think it's really cool.
- 27:32The new type system is coming along with more things like 3.9 now lets you write lowercase set bracket integers or whatever rather than from typing import capital set.
- 27:43And then you can say it in parallel, right?
- 27:45That's really nice.
- 27:46With the pipe union definition, you can do like none, pipe, a thing instead of optional.
- 27:52Yeah.
- 27:53All of those are really nice and so on.
- 27:56I suspect that a lot of people are using types for their editor but are not going any further than that with anything like mypy or continuous integration or any of those.
- 28:06Do you want to maybe speak to like the use case of both of those?
- 28:10Yeah.
- 28:10So the use of editors alone is valuable.
- 28:13You get autocomplete.
- 28:15I mean, autocomplete alone.
- 28:17You get squiggly if you do it wrong.
- 28:18Yeah.
- 28:18I mean, that's right.
- 28:19Autocomplete alone is so good.
- 28:21And I was just thinking when you were talking about that getter that was actually a setter, there's a really good chance that whoever wrote that code knew that was bad.
- 28:30And yet their tooling was such that it was so error prone for them to change the name that they were willing to live with a getter that changed values.
- 28:40Because they're like, I could break so much stuff in ways I don't understand if I don't have like a proper set of tools, like a proper editor that'll do multifile refactoring and continuous integration and all of those things.
- 28:54Right.
- 28:54And so this is sort of like in that vein of your tools now do more for you.
- 28:59Yeah.
- 28:59And so if you take a look at how costly errors are, an error of the customer is incredibly costly when you factor in support and testing and, you know, field engineering, whatever you need to resolve that customer context, not to mention loss of customer faith.
- 29:14Yeah, that's a big one.
- 29:15It's expensive for, you know, tests in the later stages of QA to catch an error too, because now our development hasn't been planning to go fix this test or this code.
- 29:25We have to stop what we're doing and go back and fix this test that maybe worked on three weeks ago.
- 29:29The best time to catch an error is immediately after you write it.
- 29:32And that's where that tooling comes in with your editors.
- 29:35As you're typing, if you can find an error, great.
- 29:38You is the least amount of costs you could have spent.
- 29:41And then the second least amount, in my opinion, is letting some sort of stack analysis tool catch it.
- 29:46Something like my pie.
- 29:47So using types, you can say, you know, I want to encode some assumptions to my code base.
- 29:52This value will never be none.
- 29:54This value may be none.
- 29:56This value may be an enter string or this string.
- 29:59If you're right that it's never none, you never have to check it for none.
- 30:03Right.
- 30:03But if you're wrong, you always have to check it for none.
- 30:06Right.
- 30:06Which is it?
- 30:07Yeah.
- 30:07We don't want to do defensive programming of checking is none.
- 30:10every single variable we create in every function in vacation.
- 30:14That would just, it wouldn't be fun.
- 30:16But your alternative, if you don't have that tooling is, all right, does this function return
- 30:20none?
- 30:20Let me go look at its source code.
- 30:22Oh, it calls five other functions.
- 30:23Let me go look at their source code.
- 30:25Oh, this calls something to the database.
- 30:27Is that a nullable feel?
- 30:28And anytime you're making someone trawl through your code base to try to answer a question of,
- 30:34can this value be none?
- 30:35You're wasting their time.
- 30:37And they're either going to delay delivering features.
- 30:41That just adds up over time.
- 30:43Or they're going to make some incorrect assumptions.
- 30:45And that's going to cause mistakes, which will lead to time and waste money.
- 30:48You've already talked about focusing your attention to put things like type annotations on the
- 30:53parts that matter and not necessarily stress about the parts that don't, especially for
- 30:56code that's being retrofitted.
- 30:57Oh, absolutely.
- 30:58I think that's not right.
- 30:59Like the thing that logs, you know, it's going to turn whatever to a string.
- 31:03And if it comes out as like, you know, some object at some address, like we'll catch it
- 31:07later and figure it out.
- 31:08But it's the core thing that you want that stuff to be right.
- 31:12But one of the things that can be challenging is the interest and the buy-in and the love for
- 31:18this idea might not be uniform across your team.
- 31:21No, no.
- 31:22You know, and I've seen the same thing for testing and I've seen the same thing for
- 31:26continuous integration, not necessarily the same person in the same thing, but you know,
- 31:30it's like if there's a person on your team that just doesn't care about the continuous
- 31:34integration and it turns off all the notifications that the continuous integration fails and then
- 31:40they keep checking in stuff and failing the build, you know, like not again, I got to
- 31:44go fix this because this person doesn't bother to check their thing and it just gets super
- 31:49frustrated.
- 31:49And I feel like probably typing has a similar analogy to that.
- 31:52It does.
- 31:53And that's why if you're in a legacy code base or even a maintained code base that doesn't
- 31:59have a whole lot of typing in it, there's alternatives you can have just beyond being strategic where
- 32:04you pick.
- 32:04There's some fantastic tooling like monkey type, which can annotate your code base for you.
- 32:09There's Google's type checker, pi type.
- 32:12It can do type checking without type annotations.
- 32:15And it does it in a little bit different philosophy than my pi, which I think is capital.
- 32:19It tries to infer based on just the values throughout your function bodies, the types should be without type
- 32:25annotations.
- 32:25So there might be ways to get the benefits without actually making the full commitment to those type checkers for just type
- 32:35annotations in general.
- 32:36There's also, I mean, tie your value to it.
- 32:39Look through your bug reports.
- 32:41If you find out that, hey, you know, we've had 12 dereferences of none in the past, you know,
- 32:49month.
- 32:49None type does not have such attribute, whatever.
- 32:52Right.
- 32:53And it's cost us X amount of dollars.
- 32:55I can now go to someone and say, look, this is costing us real money and cut like our time.
- 33:00Sometimes data speaks volumes.
- 33:02if you're having a tough time convincing people, I often say, find the data to back it up.
- 33:08Look through your bug reports.
- 33:09If I, what would we have caught?
- 33:10Oh, how much faster could we go?
- 33:12Oh, how much I'll do, do a, just even an informal survey around your developer base.
- 33:17How much more confident do you feel working in your code?
- 33:20and use that data to decide, yes, this is working or no, we need to look at alternative
- 33:25strategies.
- 33:26How much autocomplete do you get?
- 33:28I mean, that might be a winner, right?
- 33:31That would for me, actually.
- 33:32This portion of Talk Python is brought to you by masterworks.io.
- 33:37You have an investment portfolio worth more than a hundred thousand dollars.
- 33:40Then this message is for you.
- 33:42There's a $6 trillion asset class that's in almost every billionaire's portfolio.
- 33:47In fact, on average, they allocate more than 10% of their overall portfolios to it.
- 33:52It's outperformed the S&P, gold, and real estate by nearly twofold over the last 25 years.
- 33:58And no, it's not cryptocurrency, which many experts don't believe is a real asset class.
- 34:03We're talking about contemporary art.
- 34:06Thanks to a startup revolutionizing fine art investing, rather than shelling out $20 million
- 34:11to buy an entire Picasso painting yourself, you can now invest in a fraction of it.
- 34:16Few realize just how lucrative it can be.
- 34:18Contemporary art pieces returned 14% on average per year between 1995 and 2020, beating the S&P
- 34:25by 174%.
- 34:28Masterworks was founded by a serial tech entrepreneur and top 100 art collector.
- 34:33After he made millions on art investing personally, he set out to democratize the asset class for
- 34:38everyone, including you.
- 34:40Masterworks has been featured in places like the Wall Street Journal, the New York Times,
- 34:44and Bloomberg.
- 34:45With more than 200,000 members, demand is exploding.
- 34:49But lucky for you, Masterworks has hooked me up with 23 passes to skip their extensive waitlist.
- 34:55Just head over to our link and secure your spot.
- 34:57Visit talkpython.fm/masterworks or just click the link in your podcast player's show notes.
- 35:03And be sure to check out their important disclosures at masterworks.io slash disclaimer.
- 35:07I do want to move on to some other ideas because it's not all about typing, but I think typing
- 35:14unlocks a lot of these sort of durability ideas that you're covering there.
- 35:20So another one that you talked a lot about, I think is really interesting in this context,
- 35:25has to do with collection types and knowing the right data type.
- 35:30Yes.
- 35:30And that matters so much, right?
- 35:33Like somebody might use a dictionary where they should have used a set or something.
- 35:38And you're like, well, you used a dictionary, so you made me to look this up by value.
- 35:41Like, no, no, I just want to have one of everything.
- 35:43Okay, but why do we use the dictionary?
- 35:46But people, when they're new, they don't necessarily know that.
- 35:48They find the first thing that works.
- 35:50They're like, oh, a dictionary worked for this.
- 35:51We're using dictionaries.
- 35:52But beyond that, it means something for certain container types and other things, right?
- 35:57Yeah.
- 35:57I think if you look at this on a Python of, you know, there should only be one way to do
- 36:01it.
- 36:01Most people say, but there's multiple ways to do that.
- 36:03Like, I can use a dictionary.
- 36:04I can use a set.
- 36:05I can use a list and just search for unique values.
- 36:08And it's encoded in a string and you can parse it every time.
- 36:11Yeah.
- 36:11The choices you make, the abstractions you choose, communicate a certain intent.
- 36:17When you choose to use a set, that tells me I can iterate over it.
- 36:21There won't be any duplicates.
- 36:22And I don't, I won't be looking things up by key.
- 36:27When I think of a dictionary, I think of a mapping from key to value.
- 36:31The keys must be unique.
- 36:32But if all I care about was the keys and no values, like there's added cognitive,
- 36:37just dissonance of why do I have values for this dictionary?
- 36:40They're all serious.
- 36:41It doesn't make sense.
- 36:42Yeah.
- 36:42It goes back to the principle of, Lisa Sashman.
- 36:44You get surprised like, oh, this dictionary is being used as a set.
- 36:49I get it now.
- 36:50And if you're not addressing that as you find it, you're just kicking the can onto a future
- 36:54maintainer who then has to add that to the 20 other things he's trying to keep track of
- 36:59throughout their maintenance of the program.
- 37:02yeah.
- 37:03Yeah.
- 37:03The, you, you mentioned that one of my big pet peeves is, so a dictionary, I
- 37:08say is a mapping from key to value.
- 37:10That's typically a homogenous mapping.
- 37:12Every key is the same type and every value is the same type.
- 37:14But we really, really, really love dictionaries for things like JSON responses or relationships
- 37:21of data.
- 37:21And that can be so detrimental to maintain ability of code bases.
- 37:25If you're not careful.
- 37:26The problem is a type checker.
- 37:29Isn't the greatest at saying, oh, this is a dict.
- 37:32Some of the keys are strings.
- 37:34Others are bits.
- 37:35Others are decimals.
- 37:37And the values are all over the type.
- 37:39you can use a type stick to try to get around that.
- 37:42But really what you're talking about is a relationship of data.
- 37:45when you talk about dictionaries, you're getting into the, well, you, if I see, let's
- 37:50say I'm code review.
- 37:51Not only were, put this in concrete terms.
- 37:54I'm code reviewing some code.
- 37:55I see someone accessing dictionary and the key is foot.
- 37:59I have to go look at all of where that dictionary was created and modified to make sure that
- 38:05who is actually a valid field in that dictionary.
- 38:08I have no guarantees.
- 38:09Just if I see dict and a type checker, I'm sorry, a type annotation.
- 38:13So again, it's that trawling through the code base.
- 38:16Oh, this is actually coming from an API.
- 38:18Now I have to go read the API and I can't effectively code review code or maintain code.
- 38:24If I'm just reading that through without doing that every time to make sure something hasn't
- 38:28changed.
- 38:29So in this case, I'd say use a data class.
- 38:32You know, you have explicit fields.
- 38:34You can, you can lean on your tooling.
- 38:36If you mess up the field, you aren't expecting to see new fields get created and probably 95,
- 38:4399% of the time.
- 38:44Or, and I'm like, I will prefer a data class to a dictionary.
- 38:48If I have heterogeneous data almost all the time.
- 38:51Yeah.
- 38:51And maybe get it back like, like a flask API call called JSON.
- 38:56And then just jam that star star of that thing into the data class.
- 38:59Something like that.
- 39:00Yep.
- 39:00Yep.
- 39:01And I know you've talked about Pydantic on the show.
- 39:03Oh, a lot.
- 39:04I love Pydantic.
- 39:05Just, you know, define a model, let it parse that JSON response and just build that data
- 39:11class for me.
- 39:11Throw an error if it's invalid.
- 39:13And I really liked that model of, of attacking programs like that.
- 39:17I love Pydantic.
- 39:18I love how it, it tries to sort of be flexible.
- 39:21It's like, if we, if I think we can fix this, if you had a thing that is a string, but in
- 39:26the string, it really is parsable to a number and it's supposed to be a number.
- 39:29I'll just go ahead and do that type conversion for you.
- 39:32If not, give you a decent error message.
- 39:34It's really, really lovely.
- 39:36Yep.
- 39:36So if I'm, I'm working with APIs, I love Pydantic for that, that reason that you just outlined,
- 39:40but I'll often convert it to a data class or Pydantic data class so that I can say, this
- 39:45is a relationship of data and I can kind of shape how a user uses that relationship of
- 39:49data throughout the lifetime of the code.
- 39:51Yeah.
- 39:52It's an interesting tension on how much those models get used throughout all the tiers of
- 39:57your app and how much you want to keep them separate.
- 39:59Have you seen, SQL model?
- 40:01I believe it's called.
- 40:02Oh, I have not.
- 40:03I have not.
- 40:04Okay.
- 40:05here we go.
- 40:06You probably heard a FastAPI, right?
- 40:08Yeah, of course.
- 40:08Obviously that's where Pydantic got, I think it's, it's a big boost.
- 40:12So Sebastian Ramirez came out a few days ago with, this thing called SQL model and it
- 40:18already, I think it's less than a week old and has 4,000 GitHub.
- 40:21stars, which is amazing, but basically it's a merging of Pydantic and SQLAlchemy.
- 40:26Oh, fantastic.
- 40:26It has a SQLAlchemy, you didn't work model and it underlying has all the SQLAlchemy
- 40:32stuff, but it's models are actually Pydantic models.
- 40:35Yeah.
- 40:36And I think this is just another illustration of why thinking about what types things are,
- 40:41even if you're not doing type annotations, why that's so important.
- 40:43It goes back to how do we build mental models?
- 40:46How do we build these, these abstractions in our brain that we can rely upon as we
- 40:51work through our code base?
- 40:52I do think this is interesting in that you could use the same model at the data level
- 40:56internal to your app, and then you could even use the API level, but there's also people
- 41:00are saying, but maybe that's not a good idea.
- 41:02Maybe you want to separate those in, in interesting ways for like one can change and the other doesn't
- 41:08have to change.
- 41:09But yeah, I've, I see a lot of value to this thing.
- 41:11It's, it looks exciting.
- 41:12And I mean, the answer to that's going to probably be, it depends if your application needs them
- 41:17to be the same.
- 41:18Lovely surprise, make them the same.
- 41:20If they have different reasons to change.
- 41:22This is something I see a lot too.
- 41:23We all get the dry principle.
- 41:26Don't repeat yourself and rain in our head.
- 41:28And we think, oh, source code looks the same.
- 41:30We must deduplicate it.
- 41:32But if that source code can change for different reasons, you're going to add more headaches
- 41:37by deduplicating it.
- 41:38You're going to start adding special cases.
- 41:39Well, this thing needs to change, but the other thing doesn't.
- 41:43How do I reconcile that?
- 41:44Special cases.
- 41:45And soon you, you've become the very thing you've sworn to destroy as you build that out.
- 41:50It's just littered with special cases as you're trying to tie together two things that have
- 41:56two separate contexts.
- 41:58So, you know, if you want to use something like SQL model for a API level and your internal
- 42:03data model, ask yourself, do these have different reasons for change?
- 42:06Maybe, maybe in the future.
- 42:09And like a lot of this is just empathy for the future.
- 42:11When I talk about maintainable code, robust code, you have to have empathy for those future
- 42:16maintainers, put yourself in their shoes.
- 42:18Are they going to want to migrate sometime and maybe change the API that they present to
- 42:24customers or users or other developers?
- 42:25Do you want to change your database at the same time?
- 42:28If so, keep them together.
- 42:30If you want to keep that separate so that you have certain migration paths, maybe you keep
- 42:34them separate.
- 42:35And so it's going to depend case by case.
- 42:36But again, everything comes down to those first principles of what are you communicating
- 42:41with your intent when you make that decision in your code?
- 42:44Like we've touched on, you're building different things at different times under different
- 42:48constraints.
- 42:49Are you building Instagram's API, which millions of people and apps are using?
- 42:53Or are you building something really quick so you can get that app to work for marketing
- 42:58for the next thing for the week?
- 42:59Right?
- 43:00Yeah.
- 43:01If, if it's that the second one, then you, you don't want to worry about too much abstraction
- 43:05and you just want to go like, I just need these to be in sync.
- 43:07The data goes here.
- 43:08We're going to send over the API.
- 43:09We're going to be good.
- 43:10Right?
- 43:10This is going to fly.
- 43:11On the other hand, if you're building something incredibly consumed and long lived, then maybe
- 43:16you have different design patterns and care about it.
- 43:18And I think it's important to think about organizational boundaries is the users, the consumers,
- 43:24the actors in your use cases are, is there an organizational boundary separating in the Instagram
- 43:30case?
- 43:30The people who are going to be using my API, I have no control over in my organization.
- 43:35It's general public as far as I'm concerned.
- 43:38If it's just someone on my team using it, we can work through, okay, you know, I'm changing
- 43:43this API.
- 43:43Let me help you through that.
- 43:45But if it's someone outside your team or outside your organization, you're going to have a backwards
- 43:50compatibility to think about.
- 43:51You're going to have all these vast amount of things that people are going to complain about.
- 43:56And you need to think about that and say, okay, can I make these changes?
- 43:59And is it good for my user base?
- 44:01Even though I can't control them, the best I can do is entice them.
- 44:04You'll never be able to force someone to use something they don't want to.
- 44:07If you don't have that control over them, that's why we have open source forks.
- 44:10One of the ideas that I think comes up in this, this whole story, and you talk a lot about
- 44:16like inheritance, both inheritance in terms of class hierarchies and even multiple inheritance,
- 44:22but also maybe the more traditional interface style with protocols, just so that you can express
- 44:28pipe stuff separately, right?
- 44:30In interesting ways without coming up with inheritance beasts and whatnot.
- 44:35Yeah.
- 44:35So one thing I did want to give people a quick shout out.
- 44:38So we've all heard of solid principles, right?
- 44:41And I've, I really enjoyed the solid principles and I thought they were super interesting.
- 44:45I still do.
- 44:46I think they're pretty great.
- 44:48I recently came across a presentation and it was, I kind of over on Richard Campbell's
- 44:54show.net rocks, which I know people probably don't care about that now, but they actually
- 44:59talked about this thing called Cupid, which is an alternative to solid.
- 45:03I'm going to go check that out.
- 45:04And it was super, it has nothing to do with.net.
- 45:07It's just like software in general patterns.
- 45:09Like what, what do we know now, 20 years later, that doesn't necessarily make so much sense
- 45:13for solid.
- 45:14And what is the alternative?
- 45:16And he has this really cute name.
- 45:17So as people are thinking about maybe those kinds of levels, like that's a pretty interesting
- 45:22to check out.
- 45:22Yeah.
- 45:23And I like thinking of solid again, going back to first principles, there are things that
- 45:27I like about solid.
- 45:29There are things I also think get a bad rep because they're associated with heavy, heavy
- 45:35OO code bases that have class hierarchies that are just unmanageable.
- 45:40Probably multiple templates in there somehow.
- 45:42Yeah.
- 45:43And we've kind of grouped these things together.
- 45:46So an example, like one of the most misunderstood ones, in my opinion, is the list of substitution
- 45:51principle of the solid principles.
- 45:53And like it applies when you're doing duck typing in Python, which has nothing to do with
- 45:57class hierarchies.
- 45:58It doesn't have anything to do with interfaces or things like that.
- 46:02It's a turnaround substitutability.
- 46:04And so when we talk about duck typing in Python, it's, well, multiple types can represent some
- 46:09behavior.
- 46:10Maybe they support an addition method and a subtraction method.
- 46:13Can they be substituted into this function that's expecting addition and subtraction?
- 46:18And so when we think about-
- 46:19I do addition and subtraction on dates and times.
- 46:21Another might do it on like imaginary numbers.
- 46:23But the concept of adding and subtracting things, you can reuse that, right?
- 46:27Something like that.
- 46:28And so things like list of substitutability, excuse me, list of substitutability principle
- 46:33talks about how do you think about substitutability from your requirements and from your behaviors?
- 46:38And you can get value from that without ever touching a class.
- 46:42So I think all too often we lump those solid principles to a strict OO of the 90s or the knots and think that they aren't as useful.
- 46:51I'm going to have to check out Kupin and see how that's changed as well.
- 46:54I would expect that a lot of the same first principles are true, but they've kind of reframed it in a way that is more applicable to how we program today.
- 47:03I don't remember all the details exactly.
- 47:05So, but yeah, something roughly along those lines.
- 47:09I think that makes sense.
- 47:10So one thing I do also want to just sort of get your thoughts on before we leave it completely in the dust is you talked about a lot of times you've got a dictionary and it's supposed to represent some stuff.
- 47:20Maybe it's a response from an API where it says, you know, here was what you requested.
- 47:25Here was the status code.
- 47:26Here's what the cloud cost of that is.
- 47:28And here's like the, you know, some, something that looks like that maybe doesn't make sense as a dictionary.
- 47:33Maybe it gets moved into like a Pydantic model or something like that.
- 47:36Right.
- 47:37But the other one is I have 10,000 users and I want to put their email address as the key and their user object as the value.
- 47:44And given an email address, I want to know super fast, which user is that?
- 47:48Or do I have that user at all?
- 47:49In that case, the dictionary makes a lot of sense.
- 47:51Absolutely.
- 47:52But there's a super big difference to say the keys represent like the same thing across different results.
- 47:58Whereas the same data structure, a dictionary represents this heterogeneous, like not really a class, but kind of a class.
- 48:06How do you position those so that beginners understand that those are completely unrelated things that need to be thought about separately, but they kind of appear the same in code?
- 48:16Because when I'm talking to people about dictionaries and I'm teaching, they're like,
- 48:19Oh, well, why would you use a dictionary here?
- 48:21Because over here you were doing it this other way, but now it's like a database.
- 48:24Like, what are you doing with it?
- 48:25This is weird.
- 48:26Why are these not, why are they the same but different?
- 48:28So here's how I find it.
- 48:29So for the key mapping value, I would say there's a few use cases you're going to have.
- 48:35You're going to either be iterating over the dictionary to do something on every element, or you're going to be looking up a specific element.
- 48:41And that element that lookup is dynamic, typically passing in some value.
- 48:46Maybe it's a variable that contains the email address in your example.
- 48:50For something like an API response, something that might be more heterogeneous, something that should be a data class or a Pydantic model, what have you.
- 48:57You typically aren't iterating over every key.
- 49:00You're looking up specific keys, but it's static to the index, meaning you're passing in string literals between the square brackets.
- 49:07This is the key I want on this circumstance.
- 49:10You know, the name, the age, the date of birth.
- 49:13Right.
- 49:14And so you're looking up specific fields and you're building a relationship between different key value pairs.
- 49:20A name, age, and date of birth is a relationship called purse.
- 49:23With your dictionary, you're doing, or with your mapping, your key value mapping, there's no relationship between email one to user object one and email two to user object two.
- 49:33The relationship is just from key to value.
- 49:35And that's typically what I explain to people trying to discern the difference.
- 49:39That's a really interesting way to think about it because, yeah, you will almost always use static literal strings when it's the heterogeneous API response style.
- 49:48And you will almost never do that.
- 49:50Why would you say, quote, type in the email address?
- 49:53You would just have that object.
- 49:55You wouldn't need to type in, like, you would just never create that structure in the first place, which I think is really interesting.
- 50:01So, yeah, if you're dynamically passing in the keys, it's probably all the same object, but different ones of them as opposed to an API response.
- 50:10And I think that's the heart of why I really wanted to write about robust Python.
- 50:13So I've been programming for a while now, and I make a lot of decisions as a senior engineer.
- 50:18I really started to step back and ask myself, why do I make these decisions?
- 50:22Why do I choose a dictionary over a data class?
- 50:25Why do I choose a class over a data class?
- 50:27Why do I choose an acceptance test over a unit test?
- 50:30Why do I choose to do a plug-in here, but a dependency injection somewhere else?
- 50:35And I just wanted to start documenting.
- 50:37Here's why I make the decisions I did.
- 50:40Here's why, what intent I'm trying to communicate through in the hopes that we start normalizing that conversation more in our field.
- 50:47Why are we doing the things we do?
- 50:49As a beginner, it's frustrating.
- 50:51Oh, wow.
- 50:51You use a dictionary here.
- 50:53Why?
- 50:53How did you ever know to do that?
- 50:55Yeah.
- 50:56Yeah.
- 50:56And so I wanted to really capture, again, I've said it a lot.
- 51:00The first principle, why am I doing the things I'm doing?
- 51:02What are the things I often give as advice to junior programmers, intermediate programmers, too, and senior programmers?
- 51:10It's just, it was really enlightening for me to really step back and try to dissect why I do the things I do in Python and come up with, here are the valid engineering reasons behind it and try to frame that in terms of maintainability.
- 51:24Yeah.
- 51:24I think that's very valuable.
- 51:25I think it'll help people learn.
- 51:26Because it's not enough to see it by example.
- 51:28You're like, well, these both kind of work.
- 51:29It's like, yeah, but they mean something different.
- 51:32They totally communicate something different.
- 51:34A couple of thoughts from the live stream I want to share.
- 51:37Kim Van Wick out there says fantastic advice about having too much configurability.
- 51:44Far too often, I prematurely de-dupe two similar blocks of code and then find myself adding special cases.
- 51:50I wouldn't need, yeah.
- 51:51That sounds like what you were saying as well.
- 51:53Yeah.
- 51:53And so what I would say is that there's a difference between policies and mechanism.
- 51:57The policies are your business logic and the mechanisms are how you go to do something.
- 52:01Logging module in Python is fantastic.
- 52:02You're logging.
- 52:04The logger module doesn't care what you're logging, how you're logging it, when you're logging it.
- 52:09It's just the mechanism.
- 52:10To dev null, who cares?
- 52:12Yeah.
- 52:12It's all the same.
- 52:13But the what you're logging is your policy.
- 52:15And so very often I try to find a way to say, okay, how do I make my mechanisms de-duplicate?
- 52:21Because those are what I have to reuse.
- 52:23My business rules are going to change.
- 52:25They're going to change for different reasons.
- 52:26I want to make that simple to define business rules, but keep the mechanisms reusable.
- 52:30You want to be able to compose those mechanisms together.
- 52:33Also on the live stream, Mr. Hypermagnetic says, is it faster to look up a user or whatever
- 52:39from a dictionary rather than iterate over a list?
- 52:43And I think, boy, oh boy, if you've been down that path, you know there's a difference.
- 52:48This is coming from an advice from a C++ programmer who really cared about performance.
- 52:52Measure it.
- 52:52Use cases can be surprising.
- 52:54If there are times where a contiguous block of memory with a binary search is faster than
- 53:01a dictionary lookup.
- 53:02But you will not know until you measure it.
- 53:04There are also things that need to be faster than your program.
- 53:08And there are many things that don't fast in your program.
- 53:10I think it's important being aware of which one those are.
- 53:13You don't want to, not to sound cliche, the whole premature optimization is the root of all
- 53:19evil.
- 53:19Breaking that down a bit, you don't want to just optimize everything because it takes time to
- 53:25optimize things.
- 53:26And it can obfuscate your code to optimize.
- 53:28Why am I entering over a list when a dictionary lookup can be just as useful?
- 53:32If you measure the parts that need to be fast and you say, this is slow and this way is
- 53:37faster.
- 53:38As long as you have a comment and a good commit message that says why you're doing the slightly
- 53:44obfuscated way or breaking that law of least surprise.
- 53:48As long as you have those breadcrumbs for someone to follow and go, oh, it's for speed.
- 53:52This is critical performance loop of my application.
- 53:55Maybe it's the web request handler or something in a database engine.
- 53:59You want to get those breadcrumbs so people can learn why you made the choices you did.
- 54:03The last thing you want someone in five years to say, oh, they were iterating over lists because
- 54:07they don't know that a dictionary exists.
- 54:09Let me go change that and slow down your app.
- 54:11But without that measurement, without that data, it's a fruitless endeavor.
- 54:15I mean, for a lot of data in general, a dictionary lookup would be a lot faster.
- 54:19But if what you have to do is every time create the dictionary and then do the lookup, probably
- 54:26that act of creating the dictionary erases the speed up of, because you would have just,
- 54:31you're kind of looping it over anyway, right?
- 54:32So it certainly, it depends.
- 54:34But yeah, if it's pre-created.
- 54:35Yeah, don't take what I've said as prescriptive.
- 54:37Measure, measure, measure, measure.
- 54:40Yeah, absolutely.
- 54:41Absolutely.
- 54:41And the invoking just your command line application with dash MC profile is super illuminating.
- 54:49How long have I spent in a function?
- 54:51How long, how many times did I call this function?
- 54:53Where is most of my execution time spent in?
- 54:57And it might be that the bottleneck you think you have is somewhere else completely.
- 55:00Well, yeah, that's actually a really important point as well.
- 55:03If you do that C profile and you find you're spending 5% of your time in that part you're trying
- 55:09to optimize, if you could make it go to zero, it's still going to be 95% as fast, right?
- 55:15So it might be able to be sped up significantly, but it might not actually be germane to making
- 55:21your program feel any faster because it's like optimizing nothing, basically.
- 55:26And I don't want to misrepresent.
- 55:27To go back to the question on the live stream, typically a dictionary lookup will be faster than
- 55:32entering or row list.
- 55:33I expect that most of the time.
- 55:34I would not rely on that all of the time.
- 55:37Yeah.
- 55:38That's why I advocate measuring.
- 55:39Yeah.
- 55:39Measuring, measuring, measuring.
- 55:41I've definitely been in a place where I'm like, oh, this 6,000 line, super complicated
- 55:45thing that is hard to understand and work on.
- 55:47This is where it's slow.
- 55:49And no, it was just some other like wrong data structure and some other very simple part.
- 55:53But if I didn't measure, I would have gone and tried to rewrite the part.
- 55:57I was like barely understanding.
- 55:59I would have probably broken it and still would have been slow.
- 56:01Yeah.
- 56:01I forget who mentioned it.
- 56:03There's the order of writing things is you make it correct so that, and you have tests
- 56:08around it so that you know that it stays correct.
- 56:10You then work on making it clear and then you make it fast if it needs to be.
- 56:14And that last part is optional based on, is this slowing, actually slowing me down?
- 56:18Is there a business value I'm losing?
- 56:19If it, you know, there are certain things I work with.
- 56:22I, we're publishing something once a day.
- 56:25Something takes another five minutes.
- 56:26I don't really care.
- 56:28Like my time is spent better on focus on parallelization or things of that nature.
- 56:33And so it's just really understanding why things are slowing down and where a little bit.
- 56:38There's a little bit of a tangent of robust Python, but it's an interesting question to
- 56:41bring up.
- 56:41Number less, you know, is that five minutes?
- 56:43Are you waiting on that five minutes?
- 56:45No, no, no.
- 56:46You kick it off and then you go.
- 56:47Yeah, exactly.
- 56:48Then you probably don't care.
- 56:49I care at all.
- 56:50But speaking of, time, I'm sure there are a ton of people listening that are like,
- 56:55I would love to take some of these ideas, maybe using mypy or putting more types or
- 57:01looking at stuff like Pydantic and so on.
- 57:04But at the same time, I, there's a lot of pressure on me to just from the time I receive the request
- 57:12to get some feature done until the feature is done.
- 57:14And the people making that request, managers, business owners, clients, whatever, they don't
- 57:20care that much about robust Python.
- 57:23No.
- 57:24They want minimum input of money and time for output of features.
- 57:29But anyone who has done that for any extended period of time knows that that is a net negative.
- 57:35Yes.
- 57:35How do you address that?
- 57:37I'll give you some thoughts of what I've done, but how do you address that for people who
- 57:41the way I feel receiving that I want to frame the conversation for a sub it is your duty
- 57:46to deliver value as quickly as you can.
- 57:49It is also your duty to make it so that your maintainers can deliver value at the same space
- 57:54in the same space.
- 57:54So if you're making, if you're delivering value today, but hindering your ability to deliver
- 57:59a month, three months from now, that's a problem.
- 58:02Now I'm not saying jeopardize your MVP or go-to market, but making sure that the business
- 58:08people understand, I can do this, I'm not going to be able to do this again.
- 58:11The other part that I say that is just practice.
- 58:14Practice with these sort of concepts and apply them in small places.
- 58:18You can do things incrementally.
- 58:19Maybe there's a couple hundred lines of a library you have.
- 58:23Just write type annotations for that or make it more extensible.
- 58:26Find small little wins here and there.
- 58:29And as you keep working out, just this Boy Scout rule, leave the code base cleaner than you
- 58:34found it.
- 58:34So if I'm, if I'm going into something and said, you know what, these assumptions don't
- 58:37hold up anymore.
- 58:38I can't fix it all right now, but I can do one incremental step that makes it easier.
- 58:43The next time I'm in here, I take those little bites over time and slowly morph into something
- 58:48as like, okay, as we start slowing down delivery, I'm starting to make those improvements.
- 58:52And then we start speeding up back again.
- 58:55Because there is a real tension between deliver it now and how making sure that you are going
- 59:02to be able to deliver hastily in the future.
- 59:04And by no means am I advocating gold plating where, oh, make everything maintainable now.
- 59:11Because there's typically a business behind this and you don't want the business to fail.
- 59:15You need to be able to be able to ship early and often.
- 59:18And it's that often part that is often the tricky part.
- 59:21It is tricky.
- 59:22Practice, practice, practice, and target where you're applying these ideas.
- 59:27You don't have to put all that flexibility in there first, right?
- 59:30You write it one way, you get it out.
- 59:31But then you have refactoring tools.
- 59:33You have continuous integration.
- 59:34You have things that allow you to make those changes as long as you keep using them and as
- 59:39long as the code doesn't get too bad.
- 59:41And here's one of the things I've always liked seeing.
- 59:44I forget who said this.
- 59:46There's a great quote.
- 59:47It's like, to make a hard change, first make the hard change easy.
- 59:50That's the hard part.
- 59:52And then go make the easy change.
- 59:53Yeah.
- 59:54When you see, like a lot of teams do some sort of estimation of their stories.
- 59:58How big will this effort take?
- 1:00:00If you see consistently high estimates, this is always a large.
- 1:00:05We're always doing larges and extra larges.
- 1:00:07Ask yourself, what would it take to make this a small?
- 1:00:11Sometimes you use Sivanachi numbers.
- 1:00:13If this is an eight, what would it take for me to make this a three?
- 1:00:17And some of your listeners may be like, what are you talking about?
- 1:00:20But estimation, we're estimating effort.
- 1:00:22Right.
- 1:00:22Yeah.
- 1:00:23Traditionally, way, way back in the day, people used to estimate in hours.
- 1:00:26How many hours is this going to take you?
- 1:00:27And it's like, that is a granularity that we don't have.
- 1:00:31I can't tell you is it 17 or 18 hours.
- 1:00:33I can tell you is it two hours or two days, but I can't tell you whether it's 17 hours.
- 1:00:39And so when you get large estimates again and again, ask yourself, are these estimates because
- 1:00:44of necessary complexity, complexity that's inherent to my domain, or is it accidental complexity
- 1:00:49that's built up over time?
- 1:00:50I have to talk.
- 1:00:51So necessary complexity is, you know, the deep workings of a neural net or flight controller
- 1:00:57software.
- 1:00:58Like these are inherently hard problems.
- 1:01:00I can't make that simpler, not without making a whole lot of money revamping an industry,
- 1:01:05but things like tax preparation, right?
- 1:01:08Like there is a minimum set of complexity to just figure out what that answer is because
- 1:01:13the rules are complex.
- 1:01:15Yeah.
- 1:01:15But if let's take that tax, if I have to, you know, maybe add a new rule and it's just a
- 1:01:21simple multiplication somewhere, I shouldn't have to add 20 to 30 files of changes just to
- 1:01:28implement that one thing, because it's going to happen again and again and again.
- 1:01:32And so you look through these common cases and say, you know, we keep saying this is a large
- 1:01:36effort.
- 1:01:36How do I make that smaller?
- 1:01:38And then you say, oh, you know, if we just restructured things here, you often find that
- 1:01:42the same amount of effort to go make that hard change easy will pay off in one to two
- 1:01:48cycles of like, okay, now that we're doing this again and again and again, like, yes,
- 1:01:52I took an extra day longer or week longer.
- 1:01:54And again, be mindful of your schedules.
- 1:01:56I'm not saying so schedules intentionally, but find that wiggle room where you can band together
- 1:02:01with your team and find those areas.
- 1:02:03Oh, this is a place that we can get some gains back.
- 1:02:06I often like to set junior engineers on the team at these sort of tasks.
- 1:02:11They get more familiar with the code.
- 1:02:12They often don't have as many responsibilities as a senior engineer.
- 1:02:15And they can just get that understanding and they feel like, oh, I've done something that
- 1:02:20really, really matters.
- 1:02:21I really like being an engineer.
- 1:02:23Right, so you're made on a cleanup job.
- 1:02:24Yeah.
- 1:02:25And that has worked wonders for me as well.
- 1:02:27And like, it's just worked.
- 1:02:28It's a win-win.
- 1:02:29And then you're delivering those features, those same things you're doing again and again
- 1:02:33at a much greater speed.
- 1:02:35And that saves you time to go do the next thing after.
- 1:02:38My approach to this, I mean, it only works with certain groups of stakeholders, I suppose.
- 1:02:44But when somebody would ask me, how long does this feature take?
- 1:02:47It wasn't like, well, here's the essence of the feature.
- 1:02:50Like it will work and you can click the button.
- 1:02:53Here's how much it'll take to add error handling.
- 1:02:55Here's how much it'll take to add logging.
- 1:02:57Here's how much it'll add to make that work in continuous integration and have tests.
- 1:03:01And here's how much we got to do to like not add technical debt while adding this feature.
- 1:03:06Right.
- 1:03:06Instead of presenting like, well, here's your menu.
- 1:03:09Well, all I want is the feature.
- 1:03:11Just give me the feature.
- 1:03:12Right.
- 1:03:12I just say, okay, well, if the feature is three hours, the other two hours, like five hours,
- 1:03:17it can take me five hours or whatever like metric used.
- 1:03:20That is what delivering it means in a professional setting is that it is done, not that it's minimal
- 1:03:27path, zero errors and zero bad data will execute.
- 1:03:30Right.
- 1:03:31They're not the same, but it's easy to get sucked into the minimum.
- 1:03:34How quick can I do this?
- 1:03:35I bet I can do it an hour if I really fly.
- 1:03:37Right.
- 1:03:38And I think that's a trap we often fall into.
- 1:03:41Like we're as engineers, it is our, it's our responsibility to provide accurate estimates
- 1:03:46for what's best for the business.
- 1:03:48And like, if you say, oh, I can do this without tests, what you're really telling people are
- 1:03:53I can do it, but I can't guarantee it will keep working after I deploy it.
- 1:03:56Cause I will have no way of knowing I've removed that visibility of tests.
- 1:04:00Tell me, oh, this important thing that you really wanted now.
- 1:04:03No idea if it's working now.
- 1:04:05Sorry.
- 1:04:05And like, once you start framing it like that, people go, okay, yeah.
- 1:04:10Yeah.
- 1:04:10Okay.
- 1:04:10Let's see what we can do.
- 1:04:11And you might need to have some hard conversations with the people who manage us.
- 1:04:16It might be need more headcount.
- 1:04:17We don't need us.
- 1:04:18We can't take as many projects.
- 1:04:20We can't take, you know, we can't take this much complexity.
- 1:04:24Maybe, you know, maybe a worldwide pandemic is happening and are, you know, we've been severely
- 1:04:29impacted and I mean, you can't, to some degree, you can't fix poor management of something,
- 1:04:35but you can coach your way up to try to get out of it.
- 1:04:38Some people are very receptive to that.
- 1:04:39Some people are not.
- 1:04:40And in the places that aren't, I mean, you have to ask yourself, is this something that
- 1:04:45I'm going to live with or is this something that bothers me and I need to think about other
- 1:04:49things?
- 1:04:49Well, I think you're probably in a pretty good space if you're making that clear to people.
- 1:04:54So I think if you're proposing a feature or how long will it take to do this feature,
- 1:04:58then you just, you just include what that means for a feature to be done.
- 1:05:01Like it has, it, it's not like zero bad data and it works sometimes.
- 1:05:06Like it's, it works for real.
- 1:05:08The harder story is we've gotten into a bad place.
- 1:05:12We need to not add features and just refactor improvement.
- 1:05:15Like that is a different story than like, what does that mean?
- 1:05:18And that's a really tough one.
- 1:05:20Cause if I'm a business person, I'm never going to say, yes, please stop feature delivery
- 1:05:24and making money for us to go build the same thing we already have.
- 1:05:29Like that's a tough sell to a business.
- 1:05:31And I really think just an incremental approach.
- 1:05:34And again, I mentioned earlier targeting strategically.
- 1:05:36What are your most used libraries or parts of code?
- 1:05:39What are the areas with the highest bug count?
- 1:05:41Put data to that.
- 1:05:43Hey, we've had five customer complaints about a crash in your system.
- 1:05:47They're linked to this one piece.
- 1:05:48If we start doing this, we save X amount of money and we would have kept that one customer.
- 1:05:53That's the sort of thing that speaks when you're getting against those somewhat unrealistic business
- 1:05:58pressures.
- 1:05:58You have to speak on their, on their level.
- 1:06:01And I, what I'm saying is a little wrong because it's not an us versus them type mentality.
- 1:06:06You're in this together.
- 1:06:07You feel us versus them at some times, but you need to work together, make them understand
- 1:06:11here are the business implications of the choices we're making.
- 1:06:15Exactly.
- 1:06:15I mean, you're the engineer and they're the business people, but you've got to just put
- 1:06:19the situation in terms that they appreciate and they can decide if it makes sense for them.
- 1:06:25Yeah.
- 1:06:25I would also add people out there listening that if the answer is almost never, can we clean
- 1:06:32up technical debt and make this better?
- 1:06:33You probably will end up with a team over time who is full of people who don't care about
- 1:06:38erasing technical debt and making it better.
- 1:06:40And it's only just going to get worse and worse in combinatorial ways.
- 1:06:44It's, it's not where the top engineers want to be and they don't get excited about coming
- 1:06:50to work where they have to like, you know, sneak in something that's unreliable and cram
- 1:06:54new features into broken, ugly code.
- 1:06:57And something I've learned over a long time programming is almost every technical solution,
- 1:07:02there's a people or process problem at the root of it.
- 1:07:05Like there, there's a lot of things that we think, oh, code can solve this.
- 1:07:08If I just refactor this, everything will be great.
- 1:07:11But there's a people aspect of this.
- 1:07:12And I'm not putting down those people.
- 1:07:14Like everyone around you is just living, breathing human being.
- 1:07:17They all have their own hopes, their own dreams, their own obstacles, their own places in life.
- 1:07:21And we, we have to recognize that sometimes, sometimes you have to work with the people
- 1:07:26in order to solve that technical problem.
- 1:07:28So much for the, mythos of the software engineer in the basement by themselves, huh?
- 1:07:33And I think that, that, stereotype is long dead for the most part.
- 1:07:36I agree.
- 1:07:37I agree.
- 1:07:37All right.
- 1:07:38Well, we go on and on, but I think we're out of time.
- 1:07:42So thanks for all your thoughts on this and, and the book's interesting and we'll talk
- 1:07:46more about it in a second.
- 1:07:47But before we do, if you're going to write some of this code, work on some of these ideas,
- 1:07:51you know, what editor are you up to?
- 1:07:52Yeah.
- 1:07:53I use VS Code, cause I still jump between languages quite a bit.
- 1:07:57And I like the flexibility of that.
- 1:07:58for a onesie twosie, I'll use a van.
- 1:08:00Cool.
- 1:08:01Then notable PI PI package.
- 1:08:02I'm going to call it Stevedore.
- 1:08:04Cause, a package used for, plugins, doing plugin development.
- 1:08:09I think it's really neat how it uses a, the packages entry points so that you can deploy
- 1:08:15plugins as separate pip installable packages.
- 1:08:17just something I wish more people knew about.
- 1:08:19That's awesome.
- 1:08:20Yeah.
- 1:08:20One of the things we don't put, we didn't cover, but it's also part of this robust story
- 1:08:24that you tell is about extensibility, about plugins, about all those kinds of things.
- 1:08:28Right.
- 1:08:29Yeah.
- 1:08:29And that just goes back to making the common cases simple.
- 1:08:32If you, if you're doing something again and again and again, make it easy for people to
- 1:08:36do that.
- 1:08:36And extensible code is a way to do that.
- 1:08:39Yeah.
- 1:08:39Like that tax example, right?
- 1:08:40If, if you could plug in the formulas that are applied in this place and then like you just
- 1:08:44add it in and maybe it just picks it up and goes, that would be ideal.
- 1:08:47Yeah.
- 1:08:47All right.
- 1:08:48Awesome.
- 1:08:48Good recommendation.
- 1:08:49One that I had not heard of.
- 1:08:50All right.
- 1:08:51So people are interested in this idea.
- 1:08:52I assume that they can check out your book.
- 1:08:54Maybe tell people about that real quick.
- 1:08:56And then like, what else would you provide as resources or places to get started?
- 1:09:01Yeah.
- 1:09:03I think just talking to senior members on your team, talking to junior members on your team,
- 1:09:08learning how people use the code around you, keeping an ear for your, your stakeholders,
- 1:09:14your code developers, think about the code you write, think about the implications it has.
- 1:09:19I mean, just listen.
- 1:09:20Most of this is empathy.
- 1:09:22I thought I was writing a technical book.
- 1:09:24I wrote a book about empathy instead.
- 1:09:26Just didn't know it.
- 1:09:27Put yourself in other people's shoes and think about how they're going to be receiver code
- 1:09:31a month from now, a year from now, five years from now.
- 1:09:34And again, just, I mean, a lot of talks you'll see at Python or the other Python conferences,
- 1:09:41you'll see these nuggets of truth throughout them.
- 1:09:44Ask yourself, why are they making the decisions they do?
- 1:09:47And see if you can really understand the kind of the root cause of why they're using this
- 1:09:53feature, especially as new features come out with Python.
- 1:09:56A lot of great ideas in here and I had a fun time talking about them.
- 1:09:59Oh, me too.
- 1:09:59Yeah.
- 1:10:00Thanks for being here, Pat.
- 1:10:00Been an absolute pleasure.
- 1:10:02Thank you so much.
- 1:10:03You're welcome.
- 1:10:04Bye.
- 1:10:04Bye.
- 1:10:05This has been another episode of Talk Python To Me.
- 1:10:08Our guest in this episode was Patrick Viafor, and it's been brought to you by Clubhouse,
- 1:10:13Masterworks, and Assembly AI.
- 1:10:15Choose clubhouse.io for tracking all of your work because you shouldn't have to project manage
- 1:10:21your project management.
- 1:10:22Visit talkpython.fm/clubhouse.
- 1:10:25Make contemporary art your investment portfolio's unfair advantage.
- 1:10:30With Masterworks, you can invest in fractional works of fine art.
- 1:10:33Visit talkpython.fm/masterworks.
- 1:10:36Do you need a great automatic speech-to-text API?
- 1:10:40Get human-level accuracy in just a few lines of code.
- 1:10:42Visit talkpython.fm/assemblyai.
- 1:10:45Want to level up your Python?
- 1:10:47We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:10:51Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:10:56And best of all, there's not a subscription in sight.
- 1:10:59Check it out for yourself at training.talkpython.fm.
- 1:11:02Be sure to subscribe to the show.
- 1:11:03Open your favorite podcast app and search for Python.
- 1:11:06We should be right at the top.
- 1:11:08You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 1:11:13and the direct RSS feed at /rss on talkpython.fm.
- 1:11:18We're live streaming most of our recordings these days.
- 1:11:20If you want to be part of the show and have your comments featured on the air,
- 1:11:24be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:11:28This is your host, Michael Kennedy.
- 1:11:30Thanks so much for listening.
- 1:11:31I really appreciate it.
- 1:11:33Now get out there and write some Python code.
- 1:11:34I'll see you next time.