Latest / Talk Python To Me / #563: Getting Started with Rust as Python Devs
Transcript
- 0:00Michael Kennedy: Lent the entire CPython code base from scratch.
- 0:02Michael Kennedy: It takes 0.3 seconds, three blinks of an eye.
- 0:06Michael Kennedy: That is rough, and it's written in Rust.
- 0:09Michael Kennedy: So are Pydantic, Polars, uv, and Granian.
- 0:12Michael Kennedy: Rust shows up in Python in three ways.
- 0:15Michael Kennedy: Tools that happen to be written in Rust, libraries Python itself imports and runs, and servers that themselves run Python inside of Rust.
- 0:24Michael Kennedy: This episode is Rust for Python developers.
- 0:27Michael Kennedy: And Christopher Trudeau is back on Talk Python to discuss Rust and his latest course up and running with Rust.
- 0:34Michael Kennedy: The core rule is that only one thing can own a value or variable at a time.
- 0:39Michael Kennedy: Pass it around freely in Python and the garbage collector cleans it up.
- 0:43Michael Kennedy: Do that in Rust and you get a compiler error.
- 0:46Michael Kennedy: This is Talk Python To Me, episode 563, recorded Wednesday, September 9th, 2026.
- 1:10Michael Kennedy: Welcome to Talk Python To Me, the number one Python podcast for developers and data scientists.
- 1:15Michael Kennedy: This is your host, Michael Kennedy. I'm a PSF fellow who's been coding for over 25 years.
- 1:21Michael Kennedy: Let's connect on social media.
- 1:22Michael Kennedy: You'll find me and Talk Python on Mastodon, Bluesky, and X.
- 1:25Michael Kennedy: The social links are all in your show notes.
- 1:28Michael Kennedy: You can find over 10 years of past episodes at talkpython.fm.
- 1:32Michael Kennedy: And if you want to be part of the show, you can join our recording live streams.
- 1:35Michael Kennedy: That's right.
- 1:36Michael Kennedy: We live stream the raw uncut version of each episode on YouTube.
- 1:40Michael Kennedy: Just visit talkpython.fm/youtube to see the schedule of upcoming events.
- 1:45Michael Kennedy: Be sure to subscribe there and press the bell so you'll get notified anytime we're recording.
- 1:49Michael Kennedy: This episode is brought to you by Sentry.
- 1:51Michael Kennedy: You know Sentry for the error monitoring, but they now have logs too.
- 1:54Michael Kennedy: And with Sentry, your logs become way more usable, interleaving into your error reports to enhance debugging and understanding.
- 2:02Michael Kennedy: Get started today at talkpython.fm/sentry.
- 2:06Michael Kennedy: And it's brought to you by the Talk Python in Production Book, an inside look at 10 years of the real-world DevOps behind the Talk Python sites and apps.
- 2:14Michael Kennedy: Check it out at talkpython.fm/DevOpsBook.
- 2:19Michael Kennedy: Christopher, welcome back to Talk Python To Me. Always nice to hang out with you.
- 2:23Christopher Trudeau: Yeah, thanks for having me back.
- 2:24Michael Kennedy: I feel it's going to be a little old-fashioned, a little rusty.
- 2:30Christopher Trudeau: Yes, let's just start with the crap jokes and get them out of the way, yes.
- 2:34Michael Kennedy: Yeah, oh yeah, this might not actually be the final Ferris joke or whatever, but no, we're going to talk about Rust for Python devs, specifically not for Rust experts,
- 2:47Michael Kennedy: But I want to know enough Rust so that things like Pydantic, ty, if I ended up poking around them or some other extension, it would make sense, right?
- 2:57Michael Kennedy: Or maybe write a little bit of Rust to speed up some of your Python code.
- 3:00Michael Kennedy: It's obviously the most influential way to make Python extensions or core faster pieces, right?
- 3:07Christopher Trudeau: It seems to be the new way of doing things.
- 3:09Christopher Trudeau: And in fact, I saw something in the news this morning that one of the major CPU providers is switching to Rust for a lot of their device drivers and things like that.
- 3:20Christopher Trudeau: It does seem to be having its day.
- 3:22Michael Kennedy: Yeah, absolutely.
- 3:23Michael Kennedy: My joke used to be that if you switch to Rust, you're probably going to get VC funding.
- 3:28Michael Kennedy: That was like three or four years ago.
- 3:30Michael Kennedy: You know, that was when Astral and Pydantic and all that stuff happened.
- 3:34Christopher Trudeau: Now it needs Rust plus AI, but I think that's still true.
- 3:38Christopher Trudeau: So, yeah.
- 3:38Michael Kennedy: Exactly.
- 3:39Michael Kennedy: Now it's AI is the cornerstone, but if you could do Rust and AI, we.
- 3:44Christopher Trudeau: Why not?
- 3:45Christopher Trudeau: Yep.
- 3:45Michael Kennedy: Why not?
- 3:46Michael Kennedy: Just bring them all in.
- 3:47Michael Kennedy: No, it's a really cool foundation for Python things.
- 3:51Michael Kennedy: So we're going to talk about that and dive into it, compare it to Python, give some examples, give some tools, all those things.
- 3:57Michael Kennedy: But it's been a while since you've been on.
- 3:59Michael Kennedy: Give everyone a quick introduction of who you are and what you've been up to.
- 4:03Christopher Trudeau: So yeah, I'm a consultant.
- 4:05Christopher Trudeau: I mostly spend time working with teams either on architecture or technical processes.
- 4:12Christopher Trudeau: That tends to mean things like agile and lean and automation, CI/CD, all that kind of good stuff.
- 4:17Christopher Trudeau: And in my spare time, I still do a fair bit of teaching.
- 4:21Christopher Trudeau: And sometimes that's in person, sometimes that's virtual, and sometimes that's creating online courses for people.
- 4:28Christopher Trudeau: I spend a fair amount of my time in the Python space.
- 4:30Christopher Trudeau: I'm co-host of the Real Python podcast.
- 4:33Christopher Trudeau: So that tends to be where people, if they know my voice, that's from where.
- 4:36Christopher Trudeau: And lately I've been getting into Rust and figured you and I could chat about that.
- 4:42Michael Kennedy: A lot of really cool things you're doing.
- 4:44Michael Kennedy: I guess let's talk about getting into Rust.
- 4:48Michael Kennedy: First of all, what was your background?
- 4:51Michael Kennedy: Did you do C++, C, other compiled languages?
- 4:55Michael Kennedy: Because it's a shift, right?
- 4:57Christopher Trudeau: Well, so this is it, right?
- 4:59Christopher Trudeau: You hear the rust is a hard language to grasp thing.
- 5:03Christopher Trudeau: And I don't, I didn't find it that way, but I don't want to diminish people who are saying that, right?
- 5:08Christopher Trudeau: Like this isn't because I'm so much smarter or anything along those lines.
- 5:12Christopher Trudeau: It's because I have that background.
- 5:14Christopher Trudeau: I was writing C when I was 13 or 14 years old.
- 5:19Christopher Trudeau: There weren't a lot of choices when I started out.
- 5:22Christopher Trudeau: So I have a grounding and, you know, I wrote device drivers and I wrote embedded systems uh don't haven't done it in a long time but i have that grounding that rust kind of expects you to
- 5:34Christopher Trudeau: have and it's closer to the machine there's less virtualization going on uh it's a lower level language than something like python uh in fact uh bob builder russ and i were talking about this
- 5:47Christopher Trudeau: because he's got into rust recently and he came from php and python so from that it's this whole other kind of experience and he was talking about the fact that he actually thinks it's made him a better Python developer because now he's thinking about memory and stuff like that a little more
- 6:02Michael Kennedy: than you necessarily would if you've just come from Python. That's really interesting. I hadn't really thought about it because you and I are, I think, around basically the same age, at least
- 6:13Michael Kennedy: technologically speaking. And I remember getting the C++ Primer Plus. This is so nice. C++.
- 6:22Michael Kennedy: It's so much better.
- 6:23Michael Kennedy: Yes.
- 6:24Michael Kennedy: I just loved working in C++ and so on.
- 6:28Michael Kennedy: So I've never known a world where I came to Python or JavaScript or other languages where I didn't already have that experience of, you know, void star star.
- 6:39Michael Kennedy: What do I do with that?
- 6:40Michael Kennedy: Exactly.
- 6:40Michael Kennedy: These kinds of things.
- 6:42Michael Kennedy: But, of course, that makes sense.
- 6:43Michael Kennedy: You come from Python and PHP, and then you're like, whoa, why am I doing all this stuff?
- 6:47Michael Kennedy: This is crazy.
- 6:48Christopher Trudeau: Yeah.
- 6:49Christopher Trudeau: And it's, you know, a big part of it.
- 6:51Christopher Trudeau: And I think the thing that folks who are coming to it from languages like Python find difficult is that whole memory management thing.
- 6:58Christopher Trudeau: And Python basically takes care of that for you.
- 7:00Christopher Trudeau: And so if you've never had to do that before, all of a sudden it's like, I have to do what?
- 7:05Christopher Trudeau: And why do I have to do that?
- 7:07Christopher Trudeau: And it can get a little persnickety.
- 7:11Christopher Trudeau: It's concept of only one thing can own a value at a time.
- 7:17Christopher Trudeau: it has objects, but the objects belong to somebody. And in Python, you just pass those things around willy nilly and you don't worry about it. And the garbage collector takes care of it.
- 7:25Christopher Trudeau: And that often turns into a compile error in Rust. And that's on one hand, it's the beauty because it makes sure that certain kinds of bugs don't happen. On the other hand, if you're not used to
- 7:35Christopher Trudeau: it, you know, there's a, there's a joke in the Rust world that there are no bugs. It's, it's all your time isn't debugging. All your time is getting it to compile. And that's because there's a lot of that, Oh, I'm just going to pass this around and wait, I can't.
- 7:48Christopher Trudeau: And so, yeah, that there's a lot of upfront work there.
- 7:51Christopher Trudeau: And I think for a new developer, that could be very frustrating because, you know, you don't, you can't play as easily.
- 7:59Christopher Trudeau: There's the threshold to getting started with something is higher because you're constantly kind of fighting the compiler.
- 8:05Christopher Trudeau: The flip side of it is their compile messages are absolutely fantastic.
- 8:09Christopher Trudeau: They, so when errors happen, they're very, very explicit.
- 8:13Christopher Trudeau: they often include something like maybe you need to do this.
- 8:17Christopher Trudeau: And from what I saw, they were right 80 or 90% of the time.
- 8:22Christopher Trudeau: So once you figure out the language, I mean like the, not the language of Rust, but the vocabulary they use for error messages, it's very much, oh, oh, okay.
- 8:32Christopher Trudeau: So that's kicking off the borrow checker.
- 8:33Christopher Trudeau: Now I understand that.
- 8:34Christopher Trudeau: Okay.
- 8:34Christopher Trudeau: I'll go fix it.
- 8:36Christopher Trudeau: So there's a few things you kind of have to learn to get to that, but it is fairly helpful.
- 8:40Christopher Trudeau: But again, that could just be my background and remembering days of C where the compile error was being triggered from three lines before it was actually talking about where the error was.
- 8:51Christopher Trudeau: And you kind of had to zone in around roughly where it was reporting it to figure out what had gone wrong.
- 8:57Christopher Trudeau: So, yeah, there's been some advances in technology since we were tapping out bits and bytes on rocks.
- 9:03Christopher Trudeau: Yes.
- 9:04Michael Kennedy: Exactly.
- 9:05Michael Kennedy: Making sand think.
- 9:07Michael Kennedy: So I would like to just acknowledge it.
- 9:09Michael Kennedy: Six minutes, 57 seconds into the recording.
- 9:11Michael Kennedy: Borrow Checker.
- 9:12Michael Kennedy: Yeah.
- 9:13Michael Kennedy: Borrow Checker's been shouted out.
- 9:15Christopher Trudeau: Yes.
- 9:16Christopher Trudeau: Yeah.
- 9:18Christopher Trudeau: Maybe we should just do the quick version of that.
- 9:21Christopher Trudeau: We'll probably dig into it a little bit more.
- 9:22Michael Kennedy: Before you do, I just want to wax poetic.
- 9:25Michael Kennedy: Think back to the days of back in the 90s.
- 9:29Michael Kennedy: I remember when I had my C++ Primer Plus book.
- 9:33Michael Kennedy: And yes, folks, it was a book that was like the yellow pages.
- 9:36Michael Kennedy: There was no, literally the internet did not exist.
- 9:39Michael Kennedy: Well, the internet existed.
- 9:40Michael Kennedy: There was Gopher, there was Telnet, but the World Wide Web did not exist at this time, like not for four or five more years.
- 9:46Michael Kennedy: Anyway, I remember thinking, oh my gosh, this is so hard.
- 9:50Michael Kennedy: This is so much work when I'm learning it.
- 9:51Michael Kennedy: And finally, finally I got it to compile.
- 9:54Michael Kennedy: Like, oh, we're good at compiles.
- 9:56Michael Kennedy: Like, no, no, no, no.
- 9:59Michael Kennedy: That's just when the actual real hard debugging, problem solving starts.
- 10:03Michael Kennedy: But you mentioned that with Rust, that the compiler checks are a little bit stronger.
- 10:08Michael Kennedy: They check more things like proper memory management and variable sharing and things like that.
- 10:13Michael Kennedy: So I think while it was a eye-opener that compiling was only the beginning of my suffering when I was learning programming, I think compiling does mean more in Rust than it used to in other languages.
- 10:25Christopher Trudeau: Yeah, there's a whole family of bugs that have to do with memory management.
- 10:30Christopher Trudeau: And what's worse is they tend to be a tricky set of bugs.
- 10:33Christopher Trudeau: They're the kinds of things that will crash sometimes.
- 10:38Christopher Trudeau: So if you go back to C and how it stores a piece of text in memory, it has the, you know, like, let's say we're storing the word Talk Python.
- 10:48Christopher Trudeau: Well, we take the bytes for Talk Python and then we put a null on the end of it.
- 10:53Christopher Trudeau: And the compiler, when the code is working with it, it looks for that null.
- 10:56Christopher Trudeau: And that's how it knows that the string is finished.
- 10:59Christopher Trudeau: Well, if you accidentally write something longer than that, there'll be no null and it'll keep walking past that into the next chunk of memory.
- 11:07Christopher Trudeau: If you free the memory up, but you still have a pointer that points into that memory.
- 11:11Christopher Trudeau: Yep.
- 11:12Christopher Trudeau: But your computer will happily read that.
- 11:15Christopher Trudeau: And if you've got two strings in a row, what'll happen is you'll get the first string and then the lack of the null, and then you'll get the next string.
- 11:23Christopher Trudeau: And you might get a wrong message on the screen, but it won't crash your program.
- 11:26Christopher Trudeau: But if you get a string and then some memory that is a little more tricky, then all of a sudden you might actually be doing something like causing your program to fall over.
- 11:35Christopher Trudeau: So rust isn't bug free, but there is a category of bugs that it just doesn't let you create.
- 11:43Christopher Trudeau: And that makes it harder to compile, but a beauty to work with in the fact that a lot of the things that you might struggle with that are harder to debug are gone.
- 11:54Christopher Trudeau: Right.
- 11:54Christopher Trudeau: You know, I thought the nature of Python is the looseness of the type system and the dynamicism of it means you can get moving very, very quickly.
- 12:05Christopher Trudeau: But if you're not using a type checker, type mismatches are things you discover at runtime.
- 12:11Christopher Trudeau: All of that is very strict and very well managed in Rust.
- 12:15Christopher Trudeau: And so those kinds of problems just don't exist.
- 12:19Michael Kennedy: That's awesome.
- 12:20Michael Kennedy: It also takes it's also mind bending.
- 12:23Michael Kennedy: It is.
- 12:23Michael Kennedy: In some ways, right?
- 12:24Michael Kennedy: It's the way you think the way a lot of the ways you think about solving problems in C++ or C or Python can be kind of the same in Rust. Some of these limitations sort of change the algorithms
- 12:38Michael Kennedy: and the data structures that will work in those worlds. Yeah. Yep. Well, and, you know, take
- 12:42Christopher Trudeau: something as simple as an integer in Python. They're boundless, right? And if you're doing certain kinds of math, that's fantastic. There's no upper limit. Python takes care of all of that for you. It figures it out. I actually saw an article a couple of weeks ago where somebody was
- 12:56Christopher Trudeau: building a SIMD machine based on integer, based on, doing bitwise operations on massive integers, right? Thousand byte integers, and you can get away with this. And Python just happily
- 13:08Christopher Trudeau: goes, yeah, that's a really big integer. No problem. Rust is closer to the machine. So it tends to use integers the way your CPU uses integers. So you have to be aware if you're using an eight bit integer that you can't put nine bits in it.
- 13:22Christopher Trudeau: Things go wrong.
- 13:23Christopher Trudeau: Now the compiler, most of the time can catch that depends on how you're getting into that situation.
- 13:28Christopher Trudeau: And so it, it stops you from doing those things.
- 13:31Christopher Trudeau: But of course now you have to be conscious of it, right?
- 13:33Christopher Trudeau: You're making a decision when you're designing your program.
- 13:36Christopher Trudeau: How many bits am I going to store this in?
- 13:38Christopher Trudeau: And most of the time that's not a problem, but sometimes that might mean you're hitting boundaries that you wouldn't otherwise expect to hit.
- 13:45Michael Kennedy: Yeah.
- 13:45Michael Kennedy: And even weird things like it's signed or unsigned.
- 13:48Michael Kennedy: Like now you can have negative numbers, not even negative one, not allowed.
- 13:51Michael Kennedy: Yeah.
- 13:51Michael Kennedy: That means 2.17, two, two, five billion.
- 13:55Christopher Trudeau: And interesting, like a lot of that stuff is in Python, but it's buried further down.
- 14:01Christopher Trudeau: So you can get at some of those same concepts inside of Python, but if you're just starting out, you don't go digging for those things.
- 14:08Christopher Trudeau: Right?
- 14:08Christopher Trudeau: So if you're, you know, if you're playing with the network and you're trying to pack bytes together, Python has signed and unsigned and it has those sides pieces. And all of that is very, very important if you're constructing the perfect
- 14:21Christopher Trudeau: packet. But if you're just trying to do math on the command line, well, you don't need to think about that kind of thing. Rust doesn't give you the choice. And that's not Rust specific. That's most compiled languages. They don't give you the choice, right? And it's also where the speed comes
- 14:35Christopher Trudeau: from, right? So that beauty of Python's limitless integer means there has to be machinery inside of that to handle when you make it bigger than what the current chunk of memory is.
- 14:47Christopher Trudeau: And rust doesn't have that machinery.
- 14:49Christopher Trudeau: It just says, okay, I'll crash.
- 14:51Christopher Trudeau: and so it's, it's a trade-off, right?
- 14:53Christopher Trudeau: So you don't have to care for as much, but one of the reasons Python is slower is because there's the overhead that handles these kinds of things.
- 15:00Christopher Trudeau: So one of the reasons, you know, the flip side works as well.
- 15:03Christopher Trudeau: One of the reasons rust is faster is because it's optimizing for exactly what your CPU does.
- 15:10Christopher Trudeau: And that less overhead means your code runs faster.
- 15:12Michael Kennedy: Right.
- 15:13Michael Kennedy: You're never going to get a Python integer into a CPU register.
- 15:17Michael Kennedy: Right.
- 15:18Michael Kennedy: Like it's just, I don't know.
- 15:20Michael Kennedy: Maybe.
- 15:21Michael Kennedy: I remember when I came to Python, I did C++ and C#, all languages that care about the shape and size of these variables, numbers, and for 15 years.
- 15:31Michael Kennedy: And I came to Python, I'm like, I got to be doing something wrong.
- 15:34Michael Kennedy: How do I tell it again how big the number is?
- 15:38Michael Kennedy: Because what kind, like, is it just, is it a 64 bit?
- 15:41Michael Kennedy: I couldn't figure out like, what is, how do I, it's going to be a problem.
- 15:44Michael Kennedy: And then I'm like, wait, it just grows.
- 15:46Michael Kennedy: That's crazy.
- 15:46Christopher Trudeau: Yeah.
- 15:47Christopher Trudeau: Well, I think I started with Python more as a scripting glue kind of thing.
- 15:51Christopher Trudeau: And most shell languages don't have, like Python, just don't care about those things.
- 15:56Christopher Trudeau: Right.
- 15:57Christopher Trudeau: And so when you're using it loosely to glue other things together, I don't think that really kind of ever crossed my mind.
- 16:02Christopher Trudeau: And I think I got used to the idea by that time I was doing, you know, web servers and things that were bigger, more interesting projects. And I think a lot of this is where are you coming from and how are you using the tool, right? So I think for the first couple of years I was doing
- 16:14Christopher Trudeau: Python, I was writing, you know, at max 50 or a hundred line scripts to solve some immediate little problem. And it's nice not to have to worry about that kind of thing, right? So all of this really is, you know, what is the tool and how are you using it for what you're trying to accomplish?
- 16:29Michael Kennedy: Yeah. And I was coming from scientific programming, like building UIs and other type of tools for scientist type of thing.
- 16:38Christopher Trudeau: We care about the size of this number because science.
- 16:41Christopher Trudeau: That's all what your background is.
- 16:43Michael Kennedy: This portion of Talk Python To Me is brought to you by Sentry.
- 16:46Michael Kennedy: You know Sentry for their great error monitoring.
- 16:49Michael Kennedy: But let's talk about logs.
- 16:50Michael Kennedy: Logs are messy.
- 16:52Michael Kennedy: Trying to grep through them and line them up with traces and dashboards just to understand one issue isn't easy.
- 16:58Michael Kennedy: Did you know that Sentry has logs too?
- 17:00Michael Kennedy: And your logs just became way more usable.
- 17:03Michael Kennedy: Sentry's logs are trace-connected and structured, so you can follow the request flow and filter by what matters.
- 17:09Michael Kennedy: And because Sentry surfaces the context right where you're debugging, the trace, relevant logs, the error, and even the session replay all land in one timeline.
- 17:18Michael Kennedy: No timestamp matching, no tool hopping.
- 17:21Michael Kennedy: From front-end to mobile to back-end, whatever you're debugging, Sentry gives you the context you need so you can fix the problem and move on.
- 17:27Michael Kennedy: More than 4.5 million developers use Sentry, including teams at Anthropic and Disney+.
- 17:33Michael Kennedy: Get started with Sentry logs and error monitoring today at talkpython.fm/sentry.
- 17:38Michael Kennedy: Be sure to use our code, Talk Python26.
- 17:41Michael Kennedy: The link is in your podcast player's show notes.
- 17:43Michael Kennedy: Thank you to Sentry for supporting the show.
- 17:46Michael Kennedy: I do, before we get too much farther jumping into it, I do want to point out that you wrote the Up and Running with Rust course over at Talk Python.
- 17:53Michael Kennedy: So thank you for that.
- 17:54Michael Kennedy: I really enjoy this course.
- 17:56Michael Kennedy: It's both very educational and funny.
- 17:59Christopher Trudeau: I try.
- 18:00Michael Kennedy: Thank you for that.
- 18:00Christopher Trudeau: The beauty of doing this kind of stuff with a sense of humor is you don't actually have to be a comedian.
- 18:05Christopher Trudeau: It's not like everything is a joke, but you can stick some humor in once in a while.
- 18:10Christopher Trudeau: So I do wonder occasionally whether, again, because of the similar generation, half the jokes might have been aimed specifically at you.
- 18:17Christopher Trudeau: So just because you find it funny doesn't mean other people will.
- 18:21Michael Kennedy: I think they will. At least the lightheartedness.
- 18:23Michael Kennedy: We'll see what happens.
- 18:26Michael Kennedy: We'll come back to that at the end.
- 18:28Michael Kennedy: This is kind of not exactly the same.
- 18:29Michael Kennedy: It's not just that we're going to turn the course in the podcast, but it's inspired some of our concepts.
- 18:34Michael Kennedy: Now, I want to start by talking about Rust.
- 18:39Michael Kennedy: Just some examples before we dive into how is it compared to Python.
- 18:44Michael Kennedy: We've touched on a little bit of that, but there's a bunch of differences and so on.
- 18:48Michael Kennedy: But let's just appreciate some of the things like Pydantic, Ruff.
- 18:53Michael Kennedy: Give me your thoughts on the last five years of these tools.
- 18:56Michael Kennedy: have kind of supplanted a lot of things that were very well established in Python.
- 19:01Christopher Trudeau: So there's, there's, there's kind of three ways that Rust intersects with the Python world.
- 19:06Christopher Trudeau: And one has almost nothing to do with Python.
- 19:10Christopher Trudeau: It's they've used Rust to build tools that are Python tools.
- 19:15Christopher Trudeau: The, they could have just as easily done that for any other language, right?
- 19:19Christopher Trudeau: So when you talk about things like the linters and those kinds of things, they're, they're useful because they're fast.
- 19:26Christopher Trudeau: they are not, they're not really integrating with Python.
- 19:30Christopher Trudeau: They're a third party tool that you're using to make your Python better.
- 19:33Christopher Trudeau: And I think so some of the, some of the popularity in that has come out of the fact that a lot of the tools we've been using historically in the Python world have been written in Python.
- 19:43Christopher Trudeau: And so they've been very slow.
- 19:45Christopher Trudeau: And most of the time that doesn't matter.
- 19:48Christopher Trudeau: You know, there's that, you know, that programming world of, oh, I'll just go get another cup of coffee and it'll be done when it comes back.
- 19:55Christopher Trudeau: But your world shifts when you start seeing, you know, orders of magnitude, right?
- 20:02Christopher Trudeau: Like 10% faster, you're not going to notice it when you're starting to talk multiple zeros times faster, this changes things.
- 20:10Christopher Trudeau: And I think there were a couple of key libraries that started doing this and everyone kind of went, oh, wait a second.
- 20:16Christopher Trudeau: There's some, there's some value to this.
- 20:17Christopher Trudeau: And so I think there's been this real spring up of things written in Rust that make Python development easier.
- 20:24Michael Kennedy: Yeah, I think the one that was most stark to me was Ruff because it was just unreasonably fast.
- 20:33Michael Kennedy: Yes.
- 20:34Michael Kennedy: I remember running on the Talk Python training, all the courses, like that app.
- 20:39Michael Kennedy: And that app is much bigger than people think from the outside.
- 20:41Michael Kennedy: It's 170,000 lines of Python or something, which is not huge, but it's not a toy, right?
- 20:47Michael Kennedy: And so I remember running Ruff on it and it goes, found these four hours.
- 20:50Michael Kennedy: I'm like, yeah, no, you didn't.
- 20:52Michael Kennedy: Wait, wait.
- 20:54Michael Kennedy: Did I not tell it to like go into the subject?
- 20:58Christopher Trudeau: It's like, did you stop after you found four errors?
- 21:00Christopher Trudeau: I don't understand.
- 21:01Michael Kennedy: How can you be finished?
- 21:02Michael Kennedy: How can you be finished?
- 21:03Michael Kennedy: You like literally parse the entire thing for a hundred rules.
- 21:07Michael Kennedy: And it was like, enter answer.
- 21:09Michael Kennedy: I'm like, what?
- 21:10Michael Kennedy: I just don't understand.
- 21:11Christopher Trudeau: Yeah.
- 21:12Michael Kennedy: Yeah.
- 21:12Michael Kennedy: And then there's something different here, you know?
- 21:17Christopher Trudeau: Yep.
- 21:17Christopher Trudeau: I also, I tend to be fairly slow to upgrade my machines.
- 21:21Christopher Trudeau: So I'm often a couple of generations out processor wise, and it's just that much more, right?
- 21:27Christopher Trudeau: Because like when you're, when you're operating on a slow machine to begin with, and then you're trying to do something like lint a couple hundred thousand lines of code.
- 21:34Christopher Trudeau: Yeah.
- 21:35Christopher Trudeau: It makes a huge difference.
- 21:36Christopher Trudeau: It makes a huge difference.
- 21:37Michael Kennedy: It does.
- 21:37Michael Kennedy: So one of the categories is rough, which is really tooling.
- 21:39Michael Kennedy: And you can kind of forget that it's rust.
- 21:41Michael Kennedy: Like it just doesn't even really, it might as well have been written in some.
- 21:45Michael Kennedy: It could have been.
- 21:46Christopher Trudeau: Yeah.
- 21:46Christopher Trudeau: And I think that's kind of the key to this category, right?
- 21:49Christopher Trudeau: whether it's written in rust or C or anything else is kind of indifferent.
- 21:53Christopher Trudeau: It's, it's a tool.
- 21:55Christopher Trudeau: they, they're particularly with things like linters, you know, the, the, description of the Python language is publicly available.
- 22:03Christopher Trudeau: There are tools out there for compiling, for compiling language parsers.
- 22:09Christopher Trudeau: So like you can, you could have taken something, else and use that to take the definition of Python and built a thing that parses Python in any other language. It's just that Rust seems to be, has, has become the thing that is now the way to
- 22:23Michael Kennedy: do some of this stuff. Yeah, absolutely. And just give like other numbers, you know, instead of my own personal example that people can't exactly relate to for parsing for linting and pars,
- 22:33Michael Kennedy: evaluating this, the entire CPython code base from scratch is a 0.3 seconds. Yeah. That's, that's like enter the three blinks of an eye. Yeah. You know, that's pretty ridiculous. Yeah.
- 22:45Michael Kennedy: So that's one category.
- 22:46Michael Kennedy: The other category is closer to our hearts with things like Pydantic and so on.
- 22:51Christopher Trudeau: So like I said, there's kind of three modes.
- 22:53Christopher Trudeau: The second mode, and I think it's the most common one, is because Py...
- 22:58Christopher Trudeau: And this isn't really...
- 22:59Christopher Trudeau: Again, this is one of those things that's not quite Rust-specific.
- 23:02Christopher Trudeau: Python was designed from the get-go to integrate well with lower-level languages.
- 23:10Christopher Trudeau: And in fact, there's a good chunk of the Python standard library, which is really just a thin wrapper on top of the C standard library.
- 23:18Christopher Trudeau: And in fact, the older stuff in the standard library, you can actually see it.
- 23:21Christopher Trudeau: It's a little creaky in some of the naming and stuff before they kind of got consistent about how to name things.
- 23:26Christopher Trudeau: And you look at it and if you're a C programmer, you're just like, oh, I know exactly what that is.
- 23:29Michael Kennedy: At least they don't use Hungarian notation.
- 23:32Michael Kennedy: There is that.
- 23:33Christopher Trudeau: There is that.
- 23:34Christopher Trudeau: S, Z.
- 23:35Michael Kennedy: What is going on here?
- 23:37Christopher Trudeau: So Python has been designed to be able to do this.
- 23:41Christopher Trudeau: And it just turns out that I think a lot of people are coding in rust have found it easier to code than encoding in c that same interface that c
- 23:50Christopher Trudeau: extensions can use can be used by rust and so as a result libraries like pydantic libraries like polars they have written their library in rust and then with a very very thin veneer there doesn't
- 24:04Christopher Trudeau: take it doesn't take a lot of effort to expose that up and then python inside of python you can treat that like any other python module so you don't actually have to be conscious of how they
- 24:14Christopher Trudeau: And as a result of this, you end up with a lot of speed up because you use that same speed that you were talking about with rough.
- 24:21Christopher Trudeau: But now Python, which tends to be a slower language, can now access this kind of stuff.
- 24:26Christopher Trudeau: So something like Polars or Pydantic, where you're doing a lot of crunching and you want them to be fast and performative, this marriage between the dynamic library on the hard drive that is a compiled thing as a Python module,
- 24:41Christopher Trudeau: that integration has been very, very handy.
- 24:45Christopher Trudeau: And I think this is the place where Rust is starting to shine because it's a cleaner, although it can be a little frustrating, it's a cleaner language than C.
- 24:59Christopher Trudeau: There's a learning curve, but there are a lot of things it doesn't let you do.
- 25:02Christopher Trudeau: There's fewer foot guns.
- 25:04Christopher Trudeau: And as a result, it's a nice marriage between a low-level language and some higher-level concepts, right?
- 25:09Christopher Trudeau: So it has things like iterators and collections in it.
- 25:12Christopher Trudeau: And so if you're coming from Python, that's like, oh, how do I deal with that?
- 25:15Christopher Trudeau: Oh, it's the same kind of for in loop and it's the exact same thing, right?
- 25:18Christopher Trudeau: So there's enough similarity to more modern languages that this is becoming a nice sort of collection of pieces that worked well together.
- 25:27Christopher Trudeau: And in the cases of things that need to be really fast, this is a real answer.
- 25:31Michael Kennedy: Yeah, absolutely it is.
- 25:33Michael Kennedy: And taking your Rust code and exposing it as a Python package with the tools like Pyotr3 maturing that we're going to talk about obviously they they make it super easy it comes down to just
- 25:44Michael Kennedy: okay well you need to build more variants of your wheels rather than just a source only one yeah i think i have an analogy for these types of things so we have one third uh category i guess which i
- 25:54Michael Kennedy: would put as granian and other things which is a web application server that runs that is built and runs in rust but then your code and python still runs so i have i have an analogy chris tell me what
- 26:05Michael Kennedy: think here we've got the caramel dipped apple where it's caramel is python okay so we've got the caramel dipped apple where python is on the outside with like a rusty core
- 26:17Michael Kennedy: yep that would be pydantic we have maybe python maybe it's the way anyway we've got Granian and other things where it's like more like a caramel m&m on the outside it's like a
- 26:30Christopher Trudeau: hard shell of rust and then the side it's like some sort of crunchy nugget on the outside and
- 26:34Michael Kennedy: the caramel's inside yeah the protective hard outside is the rust which is granian and those types of things and then we've got the tools which i'm thinking of is just like a solid piece of caramel but that's maybe a little bit backwards i i would go with the tools are like when
- 26:49Christopher Trudeau: you've got a slices of apples and a bowl of caramel that you can dip it in so it's a separate thing but you can mix and match so yeah i think we're stretching we're officially stretching this
- 26:59Michael Kennedy: analogy and now i'm hungry but i know i know we were stretching but with your your slices of apple You've, you've perfected it.
- 27:05Michael Kennedy: Okay.
- 27:06Christopher Trudeau: So yeah, so that third category is within rust code, you can embed the Python interpreter.
- 27:11Christopher Trudeau: And so from a rust, program, you can now use an access Python.
- 27:18Christopher Trudeau: So you can kind of use Python as a scripting or, or configuration language within a larger, mechanism and something like granian where you want to actually run Python code for a web framework, that, you know, so that,
- 27:32Christopher Trudeau: that inverts the relationship we were talking about before. So yeah, so that's our three, right? So it's separate tools, the using Rust as a module inside of Python. And then the third one
- 27:43Christopher Trudeau: is using Python as a compiled library, using the interpreter as a compiled library inside of the
- 27:51Michael Kennedy: Rust object itself. Yeah, I think that sums it up pretty well. Let's talk differences. I think kind of language differences, you know, syntax differences. It feels pretty familiar, honestly.
- 28:03Christopher Trudeau: Yeah. And I was about to say, you know, to start with differences, it might actually be easier to start with what's not different. The language itself, there are some things, obviously, if you've never, if you've never seen it before, it takes a little, and that's the same with any language,
- 28:17Christopher Trudeau: but it's not going to be completely out of nowhere. If, if I hand a Python developer some fairly clean Rust, you're probably going to have an idea of what it's doing. The loop mechanisms are the same.
- 28:27Christopher Trudeau: The if else is similar. There's no L if you actually use if else. I always scratched my head
- 28:33Michael Kennedy: with L if in Python. I never understood it. Why you need a new keyword. It's such a verbose language.
- 28:37Michael Kennedy: And then it's like, well, no, this we're going to. Yes. Yeah. Why that one? I have a sneaking
- 28:42Christopher Trudeau: suspicion. It might've made something early in the early days easier to parse, but rather than parsing two keywords, it gives you a keyword. A lot of the built-in mechanisms, like it's got
- 28:52Christopher Trudeau: tuples and arrays, it's got iterables and collections. So a lot of the declaration looks like typed Python. So because it is a strictly typed language and you have to specify what everything is, you do have things like the arrow that this function returns something of this
- 29:07Christopher Trudeau: type, right? So you've got that little arrow designator. But if you're used to coding in typed python which i'm not uh then you uh then then it's readable from that perspective it is yeah
- 29:19Michael Kennedy: the types are quite quite similar uh as they you know um for the way you define them right if you have like a function or something then you just say like arrow goes to i always read that as goes
- 29:31Michael Kennedy: to pool if it like returns a pool the variables are variable name colon type right yeah yeah and
- 29:38Christopher Trudeau: And I suspect that's probably because Python type libraries was inspired by some of this stuff.
- 29:43Christopher Trudeau: I think it probably flowed the other direction, but I'm not sure about that.
- 29:47Michael Kennedy: So yeah, it's a lot of mixing in this, in the later, the things that got created later and typed later, like TypeScript is similar.
- 29:55Michael Kennedy: Yes.
- 29:56Michael Kennedy: Python types are similar.
- 29:58Michael Kennedy: Swift is similar.
- 29:59Christopher Trudeau: I think it's the same that everybody stole from C, you know, C is the granddaddy of most of the languages we use.
- 30:05Christopher Trudeau: And then I think people started adding these kinds of concepts to it.
- 30:08Christopher Trudeau: And it's like, well, if you've come from that other language, this makes it simple.
- 30:12Christopher Trudeau: So yeah, there seems to be a sort of family of how this stuff works now.
- 30:17Michael Kennedy: Yeah.
- 30:17Michael Kennedy: And someone decided all the types go after.
- 30:19Michael Kennedy: Yes.
- 30:20Michael Kennedy: Right.
- 30:20Michael Kennedy: And see, you would say like int function.
- 30:23Christopher Trudeau: Yeah.
- 30:23Christopher Trudeau: That, that, that has taken me a little bit to get used to.
- 30:26Christopher Trudeau: Yes.
- 30:27Michael Kennedy: I presume it me it's meant to be making it more readable and you see the essence, like the function name and the variable names, and then the stuff describes it after.
- 30:37Michael Kennedy: But yeah, it's always caught me off guard.
- 30:38Christopher Trudeau: I'm guessing it's because it's optional.
- 30:40Michael Kennedy: It's optional in Python, but it's not optional in Rust.
- 30:44Michael Kennedy: True.
- 30:44Michael Kennedy: Or Swift, right?
- 30:45Christopher Trudeau: Yeah, true.
- 30:46Michael Kennedy: And I'm pretty sure that Swift was inspired by, like much of Swift was inspired by Python as well.
- 30:53Michael Kennedy: Swift's an interesting thing to look at as well, like the Playgrounds, the REPL, a lot of the stuff there.
- 31:00Michael Kennedy: But okay, let's keep going.
- 31:01Michael Kennedy: Some more similarities, all right?
- 31:03Christopher Trudeau: No, I think we've hit the limit of the similarities.
- 31:08Christopher Trudeau: So it doesn't take long.
- 31:10Christopher Trudeau: It's relatively readable in the same fashion, but it doesn't take long before you have to kind of peel the top layer of that onion and then you're going to get into your differences.
- 31:19Christopher Trudeau: At the heart of it, one of the fundamental concepts is it is a compiled language.
- 31:24Christopher Trudeau: This is one of those things that I think I always find sometimes frustrates students because you end up with the, well, Python compiles.
- 31:31Christopher Trudeau: I can see the code right there.
- 31:33Christopher Trudeau: Python is a interpreted language that interprets a binary file.
- 31:39Christopher Trudeau: So when Python is compiling, it's creating a binary target.
- 31:42Christopher Trudeau: That binary target is not platform specific.
- 31:46Christopher Trudeau: It is just a, you can think of it as a data file the same way, like Excel is a data file, right?
- 31:50Christopher Trudeau: So when you, when you write a formula in Excel, you don't think of that.
- 31:53Christopher Trudeau: It's not quite compiling that formula.
- 31:56Christopher Trudeau: It's storing it in binary.
- 31:57Christopher Trudeau: And then Excel is running that formula.
- 31:59Christopher Trudeau: By contrast, Rust actually compiles to machine code for your platform.
- 32:04Christopher Trudeau: So when I come, unlike a collection of Python bytecode, I can hand you that.
- 32:10Christopher Trudeau: And I don't have to worry about what platform you're running on because your interpreter is specific for you.
- 32:14Christopher Trudeau: The bytecode is not.
- 32:16Christopher Trudeau: If I hand you my binary, if you're on the same kind of platform I am, it'll run.
- 32:20Christopher Trudeau: But if you're not, it won't.
- 32:21Christopher Trudeau: And so what Rust is actually doing there is creating a binary, tight binary file that is specific to your platform.
- 32:28Michael Kennedy: And you know what?
- 32:28Michael Kennedy: I'm jealous.
- 32:29Michael Kennedy: I'm jealous from a Rust and Python perspective.
- 32:32Michael Kennedy: You can compile it and hear, hey, I'll give you a file.
- 32:36Michael Kennedy: You can run it.
- 32:38Michael Kennedy: You know what I mean?
- 32:39Michael Kennedy: Yes.
- 32:40Michael Kennedy: I know there's a lot of reasons and it's not easy, but wow, would I love a Python --build thing and outcomes just, I don't care what's in the inner core, right?
- 32:53Michael Kennedy: You know, back to the like caramel M&Ms, but just a thing that I could put on a server, I could give to a person, I could put in Docker, and it doesn't have to have a bunch of other stuff there to make it possible.
- 33:04Christopher Trudeau: Yeah, it's a pros and cons thing, right?
- 33:06Christopher Trudeau: So your distribution is way easier, but it's very specific distribution, right?
- 33:10Christopher Trudeau: So you end up, if you're trying to aim at multiple platforms, you have to compile across all of those platforms, but the distribution of it is basically, here's the execution file, go nuts, and that's it, you're done.
- 33:22Christopher Trudeau: Or the collection of them, if you've got dynamically loading libraries.
- 33:25Christopher Trudeau: So that is definitely easier.
- 33:26Christopher Trudeau: the flip side of it is things like repls aren't technically possible because it needs to compile stuff and in fact there's some hacks out there that are kind of hilarious that are essentially
- 33:37Christopher Trudeau: repl like things that are in the background are basically recompiling a program every single time you enter a line in the repl exactly so it's actually somewhere in there yeah it's actually
- 33:49Christopher Trudeau: maintaining this program for you in order to make it look repl like and as fast as rust is i found painful i played with it once in a while and i sort of gave up and just went back to i'll have
- 34:01Michael Kennedy: my foo.rs file and i'll do it that way so yeah i could just see the background that there's like there's a fn main curly you know brace brace curly exactly and every line of rubble is jammed and
- 34:13Christopher Trudeau: then there's a cargo build cargo run yeah that's exactly what it's doing that's exactly what it's
- 34:18Michael Kennedy: doing this portion of talk python in me is brought to you by us i'm excited to talk about my first solo book, Talk Python in Production. It's an inside look at how we host all the Talk Python
- 34:29Michael Kennedy: sites, APIs, mobile apps, and way more. Here's the thing. I believe most hosting stories sold to developers and data scientists are way overcomplicated and overpriced. You've heard me say you're not Google, you're not Netflix, so you shouldn't run your infrastructure the way they
- 34:44Michael Kennedy: do. But if not that, then what? This book is both a blueprint for what I chose for Talk Python and a story arc of 10 years of running my own infrastructure from a complete newbie,
- 34:56Michael Kennedy: apprehensive to Linux, to some pretty neat infrastructures code DevOps. It covers Docker, Nginx, Let's Encrypt, self-hosted analytics and monitoring, CDN setup, framework migrations,
- 35:06Michael Kennedy: and a whole philosophy that I've termed stack native, keeping things streamlined, powerful, and free of cloud lock-in. And it's more than just your standard tech book. It comes with
- 35:16Michael Kennedy: code and figure galleries on GitHub, a discussion forum, and something unique, over an hour of audio readers briefs, short conversations that bookend each chapter to prime your focus or broaden your
- 35:28Michael Kennedy: takeaways. Oh, and 0% of this book was written by AI. Every word is mine, written over the course in high months, for better or worse. I've made the first third of the book available for free online.
- 35:40Michael Kennedy: After that, you can grab the DRM-free EPUB and Kindle editions, and I'm working on a paperback edition as well. Please check it out at talkpython.fm/devops, or just click book in the
- 35:50Michael Kennedy: nav bar on the website. It's a great way to support the podcast, and I hope it changes a bit how you
- 35:55Christopher Trudeau: think about running your apps in production. Okay, and so I guess, and that kind of, and we were already sort of talking about this, but this leads us to this idea of the strict typing mechanism,
- 36:05Christopher Trudeau: and that really comes out of this idea of the hardware, right? So your CPU has an idea of what an integer is. Your CPU has an idea of what a float is. There are different sized integers. How much memory is that integer going to be stored in? How much memory is that float going to be stored
- 36:20Christopher Trudeau: in? So not only is Rust specific about having these things, and you have to declare them when you're using them, but it also has that mapping to what your hardware does. So you have to make
- 36:32Christopher Trudeau: a decision between a signed integer versus an unsigned integer. So if you've never played with this kind of stuff before, when you stick a number in memory, that number represents just some bytes
- 36:45Christopher Trudeau: and your CPU is interpreting those bytes to mean something. And if you could have it, you could have it represent a positive number. And in the case of a single byte to it, that's from
- 36:58Christopher Trudeau: zero to 255. But if you want to also have negative numbers and store it in the same amount of space, well, then now you have to sort of map something from 0 to 255 into the negative space. And so you
- 37:09Christopher Trudeau: end up with like minus 127 to a positive 127 or 128. Let's not get into that. But essentially, the computer is interpreting those same eight bytes in a different way to represent a mix of
- 37:23Christopher Trudeau: negative and positive numbers. The downside of that is you can store less. You can only store up to was half the size of a positive number.
- 37:32Christopher Trudeau: In Python, you don't care about any of this, again, unless you're doing packets, but in Rust and C and other languages like it, you have to actually explicitly decide which of these you are using.
- 37:42Michael Kennedy: The upside is in Python, you don't care, but there is so much indirection.
- 37:48Michael Kennedy: Yes, there's a lot of overhead.
- 37:50Christopher Trudeau: Yes.
- 37:51Christopher Trudeau: And all of that overhead goes away, yeah.
- 37:53Michael Kennedy: Not only is it indirection and that overhead goes away, But can you put a bunch of Python, if I have an array of Python numbers, how are they going to land on like L1 cache?
- 38:07Christopher Trudeau: Yes.
- 38:07Michael Kennedy: They're not going, they're all random places out in the heap.
- 38:11Michael Kennedy: So, I mean, there's arenas and blocks and all that stuff to try to like get them closer together, but they're still just out there rather than I've got an array of 10 numbers.
- 38:20Michael Kennedy: Well, guess what?
- 38:21Michael Kennedy: Those numbers are contiguous in memory sort of thing, right?
- 38:25Christopher Trudeau: And you've kind of hit on something that is also very explicit in Rust.
- 38:29Christopher Trudeau: Now, you can start Rust programming without fully understanding this, but you're not going to get very far without it.
- 38:35Christopher Trudeau: It's fairly explicit about what goes on the stack and what goes on the heap.
- 38:39Christopher Trudeau: So again, if these are new concepts for you, when your program is written, the stack is where function calls happen.
- 38:46Christopher Trudeau: So when you move from one place in code into another in memory, what happens is the new address, the place you're going to, gets put onto a stack.
- 38:56Christopher Trudeau: The old address is there before.
- 38:57Christopher Trudeau: So when your function returns, it pops off the old stuff and then knows, oh, that's now the thing at the top of the stack.
- 39:03Christopher Trudeau: That's now the address I'm going to run at.
- 39:05Christopher Trudeau: And so when you add variables into, when you add parameters to your function, those are also getting put on the stack.
- 39:13Christopher Trudeau: So you end up with this little stack frame, which is the place you're going to be running and the data that goes with that function. By contrast, the heap is sort of a general space, and that is
- 39:24Christopher Trudeau: where you allocate things from memory. And longer lived things or things that you're passing around between functions tend to end up being created in the heap. And how Rust does memory management, we'll gloss over it for now, we'll get into it a little more later, I think, but how Rust does
- 39:38Christopher Trudeau: manage memory management differentiates between these two kinds of things and so again this is one of those things you you know you only think about the stack in python when it fails because
- 39:48Christopher Trudeau: you get the stack trace but otherwise you more or less ignore it whereas here once you start playing around with passing objects around whether or not you're being explicit about it that concept of am
- 40:00Christopher Trudeau: i in the stack or am i in the heap and who owns it becomes very very important and and this isn't new to Rust. This has been there in compiled languages. This is a fundamental way how modern
- 40:11Christopher Trudeau: computing machines work, but it's more exposed in Rust than it is in Python. You know, the thing I
- 40:17Michael Kennedy: think is such, to me, it was a little ironic is Python, you don't worry about pointers. You don't worry about that. You just work. And then like other languages like C, Rust, C#, you talk
- 40:29Michael Kennedy: stack, you talk heap, you talk pointers, you can dereference. Python is more pointer heavy than any of those languages because literally everything is in the heap. There's nothing that's even a
- 40:38Christopher Trudeau: number is a pointer to a thing in the heap, right? Well, this is how Python got away with not having pointers. It was everything's a pointer, so we don't have to differentiate. Yeah. Yeah, exactly.
- 40:47Michael Kennedy: That's like, if everything is a pointer, we can just treat them all like variables, right? And that made the programming simple and you don't have to think about it. But conceptually, Python,
- 40:56Michael Kennedy: everything is in the heap. Everything is a pointer. Even the number one, it's a flywheel pattern. I
- 41:04Christopher Trudeau: And even that's insane, right?
- 41:06Christopher Trudeau: Like that, yeah.
- 41:08Christopher Trudeau: I have three copies of 254, but I only have one copy of two.
- 41:14Christopher Trudeau: Sure.
- 41:15Michael Kennedy: That is really.
- 41:17Christopher Trudeau: Don't stop to think about it because, yeah.
- 41:20Michael Kennedy: Yeah.
- 41:20Michael Kennedy: For people listening are like, okay, they've gone off a rail.
- 41:23Michael Kennedy: Like they're a little, what are they talking about?
- 41:26Michael Kennedy: An optimization in CPython is the numbers, I think maybe negative five to 255, some range like that.
- 41:34Christopher Trudeau: Yeah.
- 41:34Michael Kennedy: They're pre-allocated.
- 41:36Michael Kennedy: And every time you type a literal number like 72, it's the same number.
- 41:40Michael Kennedy: It just all points at the immutable number 72 rather than creating, you know, like whatever the eight byte or four byte chunk of it is on the stack.
- 41:50Christopher Trudeau: Yeah.
- 41:50Michael Kennedy: I appreciate it makes it faster, but it's just funky.
- 41:52Michael Kennedy: Yeah, it's weird.
- 41:53Christopher Trudeau: Yeah, it's something you don't want to think about too much.
- 41:56Christopher Trudeau: A couple sort of cosmetic things, which again, if you're from Python and Python's your first language might take a little to get used to.
- 42:04Christopher Trudeau: one is brace brackets so uh like most programming languages space is not important uh and that takes i i remember it taking me a while to get used to that switching to python so i have uh patience and
- 42:18Christopher Trudeau: sympathy for people who started in python and have to go the other way this is pretty typical of most
- 42:24Christopher Trudeau: programming languages uh the it makes the parser's life easier um and i think after having coded in Python for almost two decades, I think I've come down on the side of screw the parser.
- 42:38Christopher Trudeau: So it's a little bit taking a little used to for me to get back to it.
- 42:43Christopher Trudeau: But yeah, you, you put things in brace brackets to denote them.
- 42:47Michael Kennedy: Yeah.
- 42:47Michael Kennedy: I mean, look, the job of the parser is to make your life easy.
- 42:51Michael Kennedy: Not the other way around.
- 42:52Michael Kennedy: So I get, but I have run into situations where some little bit of formatting has been off.
- 42:59Michael Kennedy: Yes.
- 43:00Michael Kennedy: On my indentation and a reformat the code broke the code because maybe I had three indentations, three spaces instead of four for who knows, maybe I hit the delete button on accident or something weird like that.
- 43:14Michael Kennedy: And I said, oh, well, look, this didn't line up right.
- 43:16Michael Kennedy: Like I'll just hit like reformat code.
- 43:18Michael Kennedy: And it's like, oh, well, that needs to go back to the left.
- 43:20Michael Kennedy: And it's like changed actually how it works.
- 43:23Christopher Trudeau: Yep.
- 43:23Christopher Trudeau: So copy and paste is problematic in Python.
- 43:28Christopher Trudeau: Yeah.
- 43:28Michael Kennedy: It's really problematic.
- 43:29Michael Kennedy: And with the braces, like it could just have no indentation.
- 43:32Michael Kennedy: It could be all gnarly.
- 43:33Michael Kennedy: It could be minified, whatever.
- 43:35Michael Kennedy: You just hit reformat and boom, it's reliably put back together well.
- 43:40Michael Kennedy: So I'm going to give Python an 80% plus, 20% minus.
- 43:45Michael Kennedy: I agree that it's nice.
- 43:47Michael Kennedy: It's not there, but it's not just there is value to it.
- 43:52Michael Kennedy: Structural correctness value to it.
- 43:54Christopher Trudeau: Yep.
- 43:54Christopher Trudeau: Yep.
- 43:54Christopher Trudeau: I also, you know, it forces programmers to behave themselves, which if you don't get your spacing right, your code doesn't work.
- 44:02Christopher Trudeau: It kind of makes the spacing consistent.
- 44:04Michael Kennedy: Yes, exactly.
- 44:05Michael Kennedy: That was what it was optimized for is like, you're going to make your code readable because you have to write it in a way that its structure and its readability match.
- 44:14Michael Kennedy: And that's beautiful.
- 44:16Michael Kennedy: But it is a little, it can have problems.
- 44:19Christopher Trudeau: Yeah.
- 44:19Christopher Trudeau: And being a veteran of the tabs versus spaces war of the nineties, eliminating that at the, at the syntax level is kind of interesting.
- 44:29Michael Kennedy: It really is like, and you know what, there was a gosh, what PyCon was it?
- 44:33Michael Kennedy: I think it was one Cleveland, maybe three, four years ago, there was a PyCon where one of the vendors clearly came.
- 44:41Michael Kennedy: It was a tool vendor that came from all the, they weren't Python specific, but they made tools for Python people.
- 44:47Michael Kennedy: and I would even maybe shout them out, or I'd call them out, but I don't even remember what it was.
- 44:52Michael Kennedy: But they were giving away t-shirts that said tabs versus spaces.
- 44:55Michael Kennedy: And you had to pick, I'm team tab, I'm team spaces.
- 44:58Michael Kennedy: I'm like, what are you doing?
- 44:59Michael Kennedy: Does nobody know that this literally is not even a choice in this language?
- 45:04Michael Kennedy: Why are you here?
- 45:06Michael Kennedy: It's a fun gag, but anyone on not team spaces is not going to run.
- 45:12Michael Kennedy: What is wrong with you?
- 45:14Christopher Trudeau: Yeah. That's a team spaces versus teams. My code won't compile. Yeah.
- 45:21Christopher Trudeau: Yeah.
- 45:22Christopher Trudeau: An interesting side effect of this that I kind of like in this language. I don't know if I've seen it elsewhere. So like most languages, it has this rust has this concept of a statement versus
- 45:32Christopher Trudeau: an expression. Most things are expressions. And in fact, your brace bracket is the definition of a new expression. And as a result of that, the end of the brace bracket can return something. So you
- 45:44Christopher Trudeau: can do an assignment to a collection of code in a brace bracket. So this ends up being kind of like an inline function. and so that's kind of interesting to me and it, it, compiles down
- 45:57Christopher Trudeau: beautifully. it's, it's got that, and then it does this weird thing where it's got implicit
- 46:04Michael Kennedy: returns. And so I really wish they had not done the implicit return. I am never ever going to be on team implicit return. I just can't. It drives me nuts. and, but the idea of having,
- 46:16Christopher Trudeau: arbitrary expressions through the brace brackets is kind of elegant. So, so yeah, one point up, one point down, whatever. and then, you know, there's some odd odds and ends, right? It's, it's,
- 46:27Christopher Trudeau: uh, FN instead of def, which quite frankly, as soon as I saw it was like, yeah, that actually makes an awful lot more sense. That tells me what it is. Def for define, define what? What am I
- 46:38Michael Kennedy: defining? FN? It's a function. That makes sense. And then one of the other things that I kind of
- 46:44Christopher Trudeau: liked a lot is, so they release a lot more frequently in Rust. So it's, there's a new, a new version coming out every six weeks, which when you come from the Python world,
- 46:55Christopher Trudeau: that sounds insane, right? Like how do you stay on top of this? But they've got this separate concept from versions that they call additions. And an addition is a three-year cycle and things
- 47:06Christopher Trudeau: stay compatible within the addition. And what's more, not only do they do that, but the compiler is able to compile to older additions. So when you compile the code, you can actually say,
- 47:18Christopher Trudeau: I want to be using an older addition. And so they have basically this forever concept of backward compatibility. So now it's still a young enough language. I suspect at some point they may
- 47:30Christopher Trudeau: give up on that. cause this, this to me smells of maintenance hell. It's fine when there's three
- 47:36Michael Kennedy: editions. What if there were 35? Yeah. but for the, for the time being, although there's been a
- 47:41Christopher Trudeau: fair amount of change in the language, in the last few years, you're not screwed by it. And it's not this constant race to stay on top of it. You can just change the edition target and you're
- 47:53Christopher Trudeau: fine. So I kind of like the idea. I think it would be kind of neat if the Python compiler, maybe, you know, if I was, I guess the changes in Python aren't as bad, so maybe it's not as extreme,
- 48:07Michael Kennedy: but I don't know. This just sort of appealed to me. Yeah, it does to me as well. I love the freshness of it. I just got a new version of Rust this morning. I was trying to update my libraries and tools, and it said there's a new version of Rust. Yes. Okay. So I think that might be a good
- 48:21Michael Kennedy: good time to maybe talk about like getting started and so on as maybe start by installing yeah uh so
- 48:30Christopher Trudeau: uh the good news is if you're in the unix world uh some sort of Linux or mac os this is uh this is a breeze you go off to the website you copy and paste the command onto the terminal and you're
- 48:40Michael Kennedy: more or less done uh we do the thing that we normally do we run arbitrary code from the internet that's right as root on our machine i'm sure it's fine yeah it's fine uh if you go off to
- 48:50Christopher Trudeau: So rest up, rustling.org.
- 48:51Christopher Trudeau: there is right on the front page.
- 48:53Christopher Trudeau: There is a little shell command that you install.
- 48:56Christopher Trudeau: This actually installs a tool called rust up rust up is kind of like pie M and that it handles installation updates of the language.
- 49:03Christopher Trudeau: It install, it installs, rust C, which is the compiler and more importantly, cargo, which is the tool.
- 49:10Christopher Trudeau: That's kind of like uv that is what you actually use.
- 49:13Christopher Trudeau: You almost never call rust C directly.
- 49:15Christopher Trudeau: So rust up handles the version management of all that kind of stuff.
- 49:19Christopher Trudeau: And once you've got that going, then you use cargo to create a new project.
- 49:26Christopher Trudeau: Again, very uv-esque here.
- 49:28Christopher Trudeau: So you would say, you know, if I'm doing hello world, it would be cargo new hello.
- 49:32Christopher Trudeau: That creates a cargo.toml, which is the equivalent of pyproject.toml.
- 49:36Christopher Trudeau: It creates a source directory.
- 49:39Christopher Trudeau: By default, it creates a git repo and a git ignore file, which drives me nuts.
- 49:43Christopher Trudeau: And I turned that off as soon as I could.
- 49:45Christopher Trudeau: I want to be in control of that.
- 49:47Christopher Trudeau: Don't do it for me.
- 49:48Christopher Trudeau: And it creates a little stub main file, which actually has a function in it.
- 49:53Christopher Trudeau: So you actually can run cargo new hello and you get a compilable program.
- 49:58Christopher Trudeau: Then you write your rest and you run cargo run and cargo run builds and runs the code for you.
- 50:05Christopher Trudeau: Now, because it's a compiled language, the result is a target that goes into the target directory.
- 50:12Christopher Trudeau: You could run that explicitly, but it's buried like three directories down.
- 50:17Christopher Trudeau: So rather than do that, you just call run and it does it for you.
- 50:20Christopher Trudeau: And there are flags you can use it to go from debug mode to release version.
- 50:25Christopher Trudeau: Your debug tends to be about 30% larger because it includes debug information.
- 50:32Michael Kennedy: While the production mode...
- 50:32Michael Kennedy: That's par for the course for people who use those things.
- 50:35Christopher Trudeau: Yeah. And in fact, on Windows, it produces...
- 50:39Christopher Trudeau: I think in Windows, it's packaged as a separate file.
- 50:42Christopher Trudeau: The debug info is in a separate file, which is, again, a standard sort of Windows thing to do.
- 50:47Michael Kennedy: Yeah, Windows often you can put, I forgot what they're called, but there's like a debug symbols that is a file that you can put like next to a DLL or an exe and it'll pull that in.
- 50:56Christopher Trudeau: And so it handles all of that kind of good stuff for you.
- 50:59Christopher Trudeau: And then this is then the thing that you would distribute if you were trying to distribute it.
- 51:05Christopher Trudeau: There's a command for building on its own and then the command for run both builds it and runs it.
- 51:10Christopher Trudeau: One of the things I'm still not quite used to is it outputs some information from the build before it actually runs the code.
- 51:18Christopher Trudeau: So you get two or three lines of info before you actually see the output from your program, which drives me nuts.
- 51:23Christopher Trudeau: But there is a dash queue to tell it not to do that so that if I'm running it, I don't want to see your compiler stuff.
- 51:29Christopher Trudeau: I want to actually have it run unless something went wrong.
- 51:32Christopher Trudeau: So yeah, cargo really is the key to doing all of this kind of stuff.
- 51:36Christopher Trudeau: Like uv, it also manages what they call crates, which are the Rust equivalent of wheels.
- 51:43Christopher Trudeau: There is a crates.io is the equivalent of PyPI.
- 51:49Christopher Trudeau: And you can write libraries and upload them there.
- 51:51Christopher Trudeau: And like with Python, this is a fairly robust community that's writing and trading code here.
- 52:01Michael Kennedy: 331,019 crates in stock.
- 52:04Michael Kennedy: We look at PyPI.
- 52:06Christopher Trudeau: think we're at 750 the last time I looked.
- 52:09Michael Kennedy: I haven't looked for either.
- 52:12Michael Kennedy: 889,000, 890,000.
- 52:14Michael Kennedy: So there are more, but I don't think that is necessarily the core metric.
- 52:18Christopher Trudeau: No, and it's also not a fair comparison because proportionately the number in crates would actually seem smaller to a Python developer.
- 52:29Christopher Trudeau: And what I mean by that is if when you're coming from the batteries included world, yeah, there aren't a lot of batteries in Rust.
- 52:34Christopher Trudeau: So something as simple as like a random number, that's a crate.
- 52:39Christopher Trudeau: And they've done this to try and keep the footprint small, which I kind of understand.
- 52:44Christopher Trudeau: For somebody who's starting out, this can be a little, so like I had this, I'm paranoid, right?
- 52:51Christopher Trudeau: So I want to know where my code is coming from.
- 52:54Christopher Trudeau: If I'm in the Python world, I trust the standard library.
- 52:57Christopher Trudeau: If I stick to the standard library, I know I have a degree of safety.
- 53:00Christopher Trudeau: Once I step outside of the standard library, I want somebody to tell me they've used it and they trust it.
- 53:05Christopher Trudeau: And, you know, for certain kinds of libraries, there's enough press that you can kind of get the idea.
- 53:10Christopher Trudeau: I haven't yet quite figured out how to get that information in the Rust world.
- 53:15Christopher Trudeau: And because things like random, which you use all the time, are actually crates, you kind of have to do a little bit of the, there's a little more rolling the dice on do I trust this code to use it kind of thing going on there.
- 53:27Christopher Trudeau: But I suspect that's still my newness to the community.
- 53:30Michael Kennedy: Yeah, perhaps. You know, Chris, just because you're paranoid doesn't mean they're not after you.
- 53:35Christopher Trudeau: Yep, that's right. That's exactly right.
- 53:38Michael Kennedy: And with the supply chain stuff, it means, I mean, it's crazy.
- 53:43Christopher Trudeau: In the world of the internet, they are out to get you. Yes, without a doubt.
- 53:47Michael Kennedy: Oh my gosh. And sometimes you hear the pounding on the door. You're like, oh my gosh, go away, please don't do that. Let's just like reflect for a minute. We talked about like cargo crates and all
- 53:59Michael Kennedy: all these things, we've seen a big revolution in Python packaging, deployment, flexibility, project management, all of those things. And much of that has actually come from the Rust side. A
- 54:13Michael Kennedy: lot of the tools like uv and others are seriously inspired by cargo, the crates, and these types of things. But this was built in a world where PyPI already existed and npm already existed. And they
- 54:26Michael Kennedy: could go really good. Ooh, that's not good. Let's do it this way. Right. So there's like this sort of interplay or this circling of these two worlds. Yeah. It's, you know, without,
- 54:37Christopher Trudeau: I'm not trying to start a flame war, but the decision that the PSF made that, managing packages wasn't really part of the language and that we should have this plethora of third-party
- 54:50Christopher Trudeau: tools to do that. I think that was a mistake. And I think the Rust people recognize that and decided to bundle this in. it's, it's a lot cleaner and there's a lot less wondering of what's
- 55:03Christopher Trudeau: going on. and, now in defense of rust, sorry, in defense, I don't know who I'm defending. Nevermind. I'm not sure whatever I'm going to defend. I'm not going to defend. Uh,
- 55:16Christopher Trudeau: the, I think the target for rust is simpler. And, part of the thing that happened in the python world is because of that dynamicism it creates all these other kinds of complications
- 55:29Michael Kennedy: um so yeah it's right my package also requires a fortran compiler exactly yeah right whereas
- 55:35Christopher Trudeau: because you're compiling these things down you some of that stuff goes away so so yeah it's it's
- 55:41Michael Kennedy: it's a challenge i agree but also wheels do exist now yep in the python world created them and they didn't before and that was like a super hard problem because yeah everything needed like all these bespoke tools just to install something interesting. And then they said, no, no, no,
- 55:55Michael Kennedy: let's just make wheels. You can just have like, why do we have to make everyone recompile everything from source? So they kind of got there. Another thing I think- They're making progress. Yeah, no, they're making progress. Yeah. Another thing I think is interesting around this is
- 56:08Michael Kennedy: you talked about the sparseness of the standard library equivalent of Rust. I feel like Python batteries included the richer standard library. It is that way because PyPI didn't exist.
- 56:21Michael Kennedy: The concept of a package manager didn't exist when Python, you know, and honestly, like what was 91?
- 56:27Michael Kennedy: Like the web didn't exist.
- 56:28Michael Kennedy: Like getting stuff afterwards was really, really hard.
- 56:32Michael Kennedy: If it were easier, they may have made different choices.
- 56:35Christopher Trudeau: Yeah.
- 56:35Christopher Trudeau: It's, it's a consequence of this language being around since the nineties.
- 56:38Christopher Trudeau: Right.
- 56:38Christopher Trudeau: So the decisions up front were, and what, and what it was designed for versus what it's grown into.
- 56:45Christopher Trudeau: you know, that's, we should all be, as software developers, we should all be so lucky as having our initial designs become questionable because 35 years later, people are still using our software
- 56:58Christopher Trudeau: all over the planet. Yeah. If people want to criticize mine because it's so popular in 30
- 57:03Michael Kennedy: years, I'd be happy as well. Yeah, exactly. All right. We've got a little bit of time left, but it's not a ton. I think let's focus on one more section and that would be, how do I go from
- 57:15Michael Kennedy: Rust land to Python land. So there are different libraries for doing this. The most common one out
- 57:20Christopher Trudeau: there is a crate called Py03. And essentially what this does is provide you with the tools
- 57:29Christopher Trudeau: to align your Rust code as if they are Python objects. And then there are a couple other tools
- 57:36Christopher Trudeau: that you can use to actually do the packaging part. So what Py03 does is it defines the interface the compiled object, which is a dynamic library, so a.so file or a.dll, and then does that in
- 57:51Christopher Trudeau: compliance with Python's ABI. And then there are tools out there that you can use, which will put those inside of a virtual environment so that Python can see them. And then in Python, you can
- 58:03Christopher Trudeau: load that code that you wrote as if it were a regular Python module written in Python.
- 58:09Christopher Trudeau: The how Py03 does this is a couple different things.
- 58:12Christopher Trudeau: One, it has Rust objects that are compatible with the Python objects.
- 58:17Christopher Trudeau: So as an example, Pyint is a Rust object that represents a Python integer.
- 58:22Christopher Trudeau: So if you need access inside of your Rust code to the integer inside of the Python space, this acts as a mechanism to get at it.
- 58:31Christopher Trudeau: It will also map Rust concepts.
- 58:34Christopher Trudeau: So rather than using pyint, you can just use, say, a int32, and py03 will take care of mapping that up to the Python integer when Python's using it in the Python side of the world.
- 58:47Christopher Trudeau: The other thing that it does is Rust has a mechanism that is macros for changing how things get compiled.
- 58:55Christopher Trudeau: And py03 ships with a bunch of macros that essentially you attach to something like a function.
- 59:01Christopher Trudeau: So if you want the function or a class to be available to Python, you wrap it with one of these macros.
- 59:06Christopher Trudeau: It's just a regular Rust function, but the macro is what does the mapping and makes it available.
- 59:13Christopher Trudeau: So with the right use of the macro, you can say things like, you know, this is my function.
- 59:18Christopher Trudeau: It's got three arguments.
- 59:19Christopher Trudeau: These arguments need to map to this, et cetera.
- 59:22Christopher Trudeau: And essentially what happens when you compile it is all of this gets put into a.so.
- 59:27Christopher Trudeau: And then you use tools like Maturin or others that then put that into a virtual environment and to handle the packaging side of things so that your Python code can use it.
- 59:38Christopher Trudeau: And from Python's perspective, once that's installed in the right place, you just import foo from bar as you would with any other module and you've got access to it all.
- 59:48Michael Kennedy: Interesting.
- 59:48Michael Kennedy: Now, it doesn't have to be all or nothing as well.
- 59:51Michael Kennedy: For example, remind me how to do this because I forgot how to do it.
- 59:54Michael Kennedy: but you can create a project that has some Rust code and some Python code and then build that into a wheel.
- 1:00:01Michael Kennedy: But you could say only part of my code is gonna be Rust and the rest of it that's not performance critical, that's all Python all day long.
- 1:00:09Christopher Trudeau: Yeah, so for example, if you look at, if you pay close attention when you install Polars, you're actually getting two wheels, one of which is a universal wheel, which is because it's universal, it only contains Python code.
- 1:00:22Christopher Trudeau: And the other of which is it's figured out what platform you're on and gives you the actual compiled Rust version of the Polars library. So they've kind of got these two things going on. Now, I don't know Polars well enough. I've never looked at their source code, so I don't know what they've
- 1:00:37Christopher Trudeau: got in each one of those packages, but they've built something that is comprised of both of those things. In their case, it's in two separate wheels. It doesn't have to be. And essentially,
- 1:00:47Christopher Trudeau: you're using a tool like Mature and it takes care of this for you. So if you're after a, if you're after building a library where there's a part of it that has to be very performant, but you want to write most of it in Python because, you know, it's easier to code in,
- 1:01:03Christopher Trudeau: then there's, you basically do that and Maturin will let you bundle all of that up.
- 1:01:07Christopher Trudeau: And this is no different than any other plugin mechanism. It's just that these are the tools that Rust provides to build those kinds of plugins. So if you think of tools like Polars or NumPy or any others that do this kind of concept where some of it's written in a lower
- 1:01:21Christopher Trudeau: level language, I O three just lets you do that.
- 1:01:23Michael Kennedy: I think there's a lot of, a lot of low hanging fruit for people to go apply a profiler to their code and say, no, it really only matters at least 20 lines of code here.
- 1:01:33Michael Kennedy: Yeah.
- 1:01:33Michael Kennedy: What if?
- 1:01:34Christopher Trudeau: Yeah.
- 1:01:35Christopher Trudeau: The challenge you have to pay is every time you do this, you're crossing a boundary and there is a cost to crossing that boundary.
- 1:01:43Christopher Trudeau: So, there, if you're writing the code in such a fashion that you're constantly going back and forth or your objects are constantly going back and there's overhead to that so writing in and rust doesn't guarantee that it will be faster
- 1:01:56Christopher Trudeau: could make it slower it could make it slower like with everything uh but if you're doing something you know it's something like polar's where you're doing big number crunching uh and you're you know you're calling into the api and then letting it crunch and then it spit another answer out then
- 1:02:10Michael Kennedy: yeah you can you can see a significant speed up yeah or pydantic where it comes in as json anyway and it's got to be transformed to something, let that happen in Rust and then talk to it.
- 1:02:21Michael Kennedy: So yeah, this is really good.
- 1:02:23Michael Kennedy: I'm going to have Pablo and Laszlo on to talk about the new profiler that's in 3.15.
- 1:02:30Michael Kennedy: That's really interesting, the profiling module.
- 1:02:31Michael Kennedy: One of the things that's fascinating about that, I don't have anything in production in 3.15.
- 1:02:37Michael Kennedy: All my stuff's in 3.14 or lower, like older.
- 1:02:41Michael Kennedy: Now, one of the things that's cool about the new profiler is you can attach it to stuff running in production, profile it, and then walk away.
- 1:02:49Michael Kennedy: You know, like, hey, let's just go, it's running.
- 1:02:52Michael Kennedy: A bunch of people are using this app, like it's an API or something.
- 1:02:55Michael Kennedy: Let's just hook onto it for 30 seconds, get some data and step back.
- 1:02:59Michael Kennedy: And then maybe you could look at, oh, actually, if we could just make this one part faster, that would really be a big deal.
- 1:03:05Michael Kennedy: So I think the possibility for this is just getting easier.
- 1:03:08Christopher Trudeau: Yeah, well, and, you know, the general advice I give folks when I talk about optimization is don't and then measure, right?
- 1:03:16Christopher Trudeau: So when you're trying to figure it out upfront, it doesn't matter how good you are at this.
- 1:03:21Christopher Trudeau: You tend to make the wrong assumptions eventually.
- 1:03:25Christopher Trudeau: And so, yeah, build something, then profile it, and then figure out where you're spending all your time.
- 1:03:30Michael Kennedy: Yeah, I've had a couple of experiences.
- 1:03:32Michael Kennedy: I won't go into the details of it, but I've told it a time or two way, way back in the day where I was so wrong.
- 1:03:40Michael Kennedy: Yep.
- 1:03:40Michael Kennedy: So wrong about what was slow and what was fast.
- 1:03:43Michael Kennedy: And if I had just pursued my intuition, it would have been months of bad choices.
- 1:03:47Christopher Trudeau: Yeah.
- 1:03:48Christopher Trudeau: And there's a concept called Amdahl's Law, which is essentially, I'm going to oversimplify it, but if your code is spending 10% of its time in that place,
- 1:03:59Christopher Trudeau: speeding that up by 2x is only ever going to get you a 10% gain because your code's spending the other 90.
- 1:04:07Christopher Trudeau: There's a diminishing return aspect to it as well.
- 1:04:10Christopher Trudeau: And as programmers, I think we often get tied up in the, oh, wouldn't it be cool if I made this code three times harder to read and it'll be, you know, half a millisecond faster.
- 1:04:20Christopher Trudeau: And how often do you call that?
- 1:04:22Christopher Trudeau: Once a year.
- 1:04:23Christopher Trudeau: Oh, okay.
- 1:04:23Christopher Trudeau: Well, there's a month of your life you got back in order to optimize by a millisecond, right?
- 1:04:30Christopher Trudeau: Where you got to find the stuff that is actually causing the problem.
- 1:04:33Michael Kennedy: Yeah.
- 1:04:34Michael Kennedy: You gave a 50% speed up example.
- 1:04:36Michael Kennedy: Like, let's take it to an insane level.
- 1:04:39Michael Kennedy: 20% of your code, 20% of time you spend in some bit of code.
- 1:04:43Michael Kennedy: If you could make it infinitely faster, the best you're going to achieve is your program is going to be 20% faster.
- 1:04:50Michael Kennedy: You know, maybe, oh, I was running this on a single CPU thread.
- 1:04:54Michael Kennedy: I'm going to actually get a GPU machine with a crazy thing and do a bunch of GPU programming.
- 1:04:59Michael Kennedy: And I can parallelize this and I'll get it down to a thousand times faster.
- 1:05:03Michael Kennedy: Is that worth a 20% speed up?
- 1:05:05Michael Kennedy: If it takes five milliseconds, you've saved one millisecond.
- 1:05:09Michael Kennedy: hooray look how much harder your life and how much more expensive deployment is and so on right yeah yeah so it's certainly uh something that people should keep in mind all right well i think
- 1:05:19Michael Kennedy: let's let's wrap things up here rust is super interesting i think it's got a place in python and even if you don't want to write rust a lot of these really important libraries are
- 1:05:31Michael Kennedy: somewhat backed by rust so you want to read them and maybe contribute to the to the caramely shell or the noogity inner, but you still kind of want to understand the bits. I think maybe a quick
- 1:05:41Michael Kennedy: shout out to your course. People should definitely give this a listen or a watch. Just talkpython.fm, click on course at the top. Rust will be, the Rust course will be right at the top of that list.
- 1:05:52Christopher Trudeau: Yeah, it was fun to build. I hope people enjoy it.
- 1:05:54Michael Kennedy: Yeah, I think they will. And more importantly, more broadly, I suppose, people want to get started with Rust. You've inspired them, Chris. They're ready. What do you tell them?
- 1:06:04Christopher Trudeau: Rustlang.org is pretty much the place to start.
- 1:06:08Christopher Trudeau: It's remarkably well documented.
- 1:06:10Christopher Trudeau: There's a lot of good guides and things out there.
- 1:06:13Christopher Trudeau: The documentation right on that site, they've got the Rust book right there.
- 1:06:18Christopher Trudeau: It's quite easy to follow.
- 1:06:20Christopher Trudeau: It has a lot of really, really good examples in it.
- 1:06:24Christopher Trudeau: So that's definitely a place to go.
- 1:06:26Christopher Trudeau: The other space, just a bit of a shout out would be, there's a awesome list called Awesome Python RS.
- 1:06:33Christopher Trudeau: And it's just a massive list of the tools and libraries that use Rust in the Python space.
- 1:06:39Christopher Trudeau: So if you're looking for, rather than like education book examples, you're looking for places that actually use it and you want to, and you want to troll through some code, that's a great
- 1:06:50Christopher Trudeau: place to go looking for interesting libraries to take a look at. Yeah. I second that. I'm,
- 1:06:55Michael Kennedy: I'm such a sucker for awesome lists. Yes. That could be, you want to watch a movie? I found a new awesome list. I'm just going to poke around this for like the next half hour, if you don't
- 1:07:03Christopher Trudeau: mind, you know? Yeah. And, you know, there's some very classic examples on this list of like drop-in replacement for speed things, right? So there's a cryptography library and there's a JSON library,
- 1:07:15Christopher Trudeau: both of which are basically drop-in replacements for stuff from the standard library. And because they're written in Rust, they're screamingly faster. So, you know, that example of looking for the thing that you need to optimize, there's some good ideas in there that you can dig into.
- 1:07:30Michael Kennedy: Yeah. And you know, I gave you the example of like, well, we could just rewrite this bit of your slow code and rust. It might already be written as a library.
- 1:07:38Christopher Trudeau: Someone else may have done it as well. Yes.
- 1:07:40Michael Kennedy: Yeah. Just swap, swap your JSON parsing library or whatever. Right.
- 1:07:43Christopher Trudeau: And, and a lot of the, Python things that are like Python libraries that use rust, a lot of them are actually just thin wrappers to existing rust libraries.
- 1:07:54Christopher Trudeau: So that somebody is rather than writing something from scratch, they're like, Hey, there's this neat library in Rust that does this thing that I like, and I wish it was in Python.
- 1:08:03Christopher Trudeau: And they write like four lines of code that are essentially the API wrapper down to make it, expose it as a module.
- 1:08:10Christopher Trudeau: And now we can take advantage of the fact that there's this whole other community that's trying to do these efficient things.
- 1:08:16Michael Kennedy: And we don't have to trust the suitability and correctness of somebody saying, hey, I spent a weekend rewriting the JSON parsing.
- 1:08:24Christopher Trudeau: Like, ah, brightening.
- 1:08:26Christopher Trudeau: These are things with thousands of stars and many contributors because the Rust community themselves are using them, right?
- 1:08:33Michael Kennedy: Right, right.
- 1:08:33Michael Kennedy: And if you just wrap it, you're pretty safe.
- 1:08:36Christopher Trudeau: Polars is an example, right?
- 1:08:37Christopher Trudeau: Polars is a Rust library for Rust programmers.
- 1:08:40Christopher Trudeau: And then there's a Python thing on top of it, right?
- 1:08:43Christopher Trudeau: So you're getting not just the Python people using it, but the Rust people using it as well.
- 1:08:48Michael Kennedy: What is that?
- 1:08:49Michael Kennedy: A caramel dipped apple equivalent version or something like that?
- 1:08:52Christopher Trudeau: Yes.
- 1:08:53Christopher Trudeau: I don't know.
- 1:08:53Christopher Trudeau: There's caramel everywhere by the time we're done.
- 1:08:55Christopher Trudeau: So it's a messy, messy kitchen.
- 1:09:00Michael Kennedy: It was delicious.
- 1:09:01Michael Kennedy: It was a delicious episode, Chris.
- 1:09:03Michael Kennedy: Thank you for being here.
- 1:09:03Michael Kennedy: That's all right.
- 1:09:04Christopher Trudeau: Happy to be here.
- 1:09:05Michael Kennedy: Yeah, bye-bye.
- 1:09:06Michael Kennedy: This has been another episode of Talk Python To Me.
- 1:09:09Michael Kennedy: Thank you to our sponsors.
- 1:09:10Michael Kennedy: Be sure to check out what they're offering.
- 1:09:11Michael Kennedy: It really helps support the show.
- 1:09:14Michael Kennedy: This episode is brought to you by Sentry.
- 1:09:16Michael Kennedy: You know Sentry for the error monitoring, but they now have logs too.
- 1:09:19Michael Kennedy: And with Sentry, your logs become way more usable, interleaving into your error reports to enhance debugging and understanding.
- 1:09:27Michael Kennedy: Get started today at talkpython.fm/sentry.
- 1:09:31Michael Kennedy: And it's brought to you by the Talk Python in Production Book, an inside look at 10 years of the real-world DevOps behind the Talk Python sites and apps.
- 1:09:39Michael Kennedy: Check it out at talkpython.fm/DevOps book.
- 1:09:42Michael Kennedy: If you or your team needs to learn Python, we have over 270 hours of beginner and advanced courses on topics ranging from complete beginners to async code, Flask, Django, HTML, and even LLMs.
- 1:09:55Michael Kennedy: Best of all, there's no subscription in sight.
- 1:09:58Michael Kennedy: Browse the catalog at talkpython.fm.
- 1:10:00Michael Kennedy: And if you're not already subscribed to the show on your favorite podcast player, what are you waiting for?
- 1:10:05Michael Kennedy: Just search for Python in your podcast player.
- 1:10:07Michael Kennedy: We should be right at the top.
- 1:10:08Michael Kennedy: If you enjoyed that geeky rap song, you can download the full track.
- 1:10:11Michael Kennedy: The link is actually in your podcast blur show notes.
- 1:10:14Michael Kennedy: This is your host, Michael Kennedy.
- 1:10:16Michael Kennedy: Thank you so much for listening.
- 1:10:17Michael Kennedy: I really appreciate it.
- 1:10:18Michael Kennedy: I'll see you next time.
- 1:10:45Christopher Trudeau: I think is the norm.
- 1:11:16Christopher Trudeau: Продолжение следует...