From the course: Using Rust with Python

Introduction: Rust and Python - Rust Tutorial

From the course: Using Rust with Python

Introduction: Rust and Python

- [Instructor] Integrating Python and Rust in the GenAI era is a very interesting proposition because it takes looking at the strengths of both languages and deciding what are the integration points? As well as when is it best to use Python and when is it best to use Rust? And how does generative AI, in particular, enhance both languages? So first up, let's take a look at Python here on the left. We have readability, legacy, you know, support, libraries. It's very popular. It's, in fact, one of the most popular languages in the world. It has a great interactive feedback loop. So what Python is designed for historically is for the human. So, Python is very productive for people. That's why they like it. And if you're going to build a web app or a command line tool, or you know, build some kind of script, it's hard to beat Python for that initial productivity and that feedback loop. On the other hand, there are some limitations that Rust solves. And that Rust is a newer language, right? So it has a modern-based story for it, and it has support for things that are not available in Python. Python doesn't have true threads, but Rust does have true threads. And the concurrency techniques in the compiler are also very advanced in that they check for race conditions and other known errors so that you get very robust code. And also, the performance is one of the best languages in the world. It has, you know, machine level type performance and also has the ability to have low energy and also has a lot of safety features. So really, Rust has this, you know, ability to go past the legacy issues that Python has because it was built in a different era where multi-core systems really were a common, you know, occurrence. And also, safety has become a bigger and bigger issue. Also, likewise with Python, it's gone through many different iterations of packaging systems. There's many competing solutions with Rust. There's actually one solution which is Cargo, and it's extremely robust, very simple. So there's some pros and cons to both languages. So, the intersection here is where we see people doing things with tooling, with performance optimization. A good example is if you were using a linting tool that was pure Python, the performance is just very slow. But you could rewrite that linting tool, like in the case of Rust, where the performance could be 100 times or better. And on a large code base, this could be substantial in terms of performance. Also, if you had something that was a, you know, inference server or a web server or some kind of server of any kind, you really don't want to write that on Python. So, people will wrap something that you do in Rust with Python, and you have the ability to do both. Now the curve ball here is generative AI in that it is really going to enhance the core features of both of the languages because of the fact that it can be up to 80% of the code that you write. So again, Python is designed for humans, so the productivity with humans is very high. But in terms of Rust, which is also has a pretty good story for being productive, but it is able to work at a lower level, you can see that generative AI has, in many cases, a stronger impact on the Rust performance than the Python performance because of the fact that the Rust language is closer to, you know, you know, performance level, you know, type of code. And so, generative AI is a very good combination with Rust because the compiler will catch many of the issues that are hallucination issues with generative AI. Python doesn't have the concept of a compiler, it doesn't have the concept of runtime error checking or safety features built into it. It's not designed for that. It's designed for productivity with humans. So with the new era of generative AI, I think what we're seeing is that it actually is a very good fit for building out Rust code because Rust itself is so robust against error. So we can see here on the left, we have the readability, which is the productivity with generative AI, but on the right, we have performance and safety here. And so the intersection shows that we have a slight tilt here towards if you are going to be using generative AI to write code, and I believe most people are, there starts to become a more compelling story for using more Rust in your code base. So these are just a few things to think about when you're dealing with both Python, Rust, and the integration of them in the generative AI era.

Contents