Python to Rust: Breaking Down 3 Big Obstacles | by Dennis Bakhuis | Dec, 2023


Python pro to Rust rookie — a data scientist’s transition tale

Figure 1: The snake and the crab. (Crab: Romina BM; Snake: Mohan Moolepetlu; composition by author).

Everybody around me knows that I am a big fan of 🐍 Python. I started using Python about 15 years ago when I was fed up with Mathworks Matlab. While the idea of Matlab seemed nice, after mastering Python I never looked back. I even became a sort of evangelist of Python at my University and “spread the word”.

The ability to code does not make you a software developer.

At my current employer TenneT, a large transmission system operator in the Netherlands and Germany, we are building a document parsing and validation solution with a team of about 10 people. Building such a solution, especially in a team, is much harder than I thought. This also made me more interested in proper paradigms of software engineering. I always thought that my code is not too bad, but after looking at working from my software engineer friends: man there is so much to learn!

As I learned about topics like strong typing, SOLID principles, and general programming architectures, I also glanced at other languages and how they solved the problem. Especially Rust caught my eye as I often saw Python packages that were based on Rust (e.g. Polars).

To get a proper introduction to Rust I followed the official Rustlings course which is a local Git repository with 96 small coding problems. While it was quite doable, Rust is very different than Python. The Rust compiler is a very strict fellow that does not take maybe for an answer. Below are my three major differences between Rust and Python.

Disclaimer: while I am quite proficient with Python, my other languages are a bit Rusty (pun intended). I am still learning Rust and I may have understood parts incorrectly.

Figure 2: We made it to the finish line (screenshot by author).

Ownership and borrowing are probably the most fundamental aspect of the Rust programming language. It is designed to ensure memory safety without the need of a so called garbage collector. This is a unique concept to…



Source link

Leave a Comment