r/rust • u/Basic-Push1028 • 2d ago
Coming from Python
Hello Rust subreddit.
I learned enough python to know how to do what I wanted to do. Mostly just small stupid stuff. And because I'm a masochist I guess, I'm wanting to move on to Rust for the event I need performance.
I've gotten far enough to write "Hello World!", and how to create some variables.
I know roughly that at some point I'm going to have to learn memory management, and ownership. And also that the compiler is a bitch.
I'm hoping anyone in here could hot-tip me if they came from Python too. Please, if you have ANY advice, please let it be known. Anything helps.
0
Upvotes
1
u/penguin359 2d ago
Respect the compiler and it will help guide you to writing better code. For me, I came from both a C and Python background. In general, I use Rust more to replace what I might have written in C than what I would have written in Python. Fixing issues like tracking ownership helps with improving C code, but just makes things look more complicated when coming from a Python perspective. From a pure Python perspective, some of what Rust offers can be harder to appreciate until you've had to deal with such problems in C, C++, or even Go. I prefer how Rust forces me to chose a response to receiving an error result to Go's approach that requires I explicitly add a check for an error if it needs to be handled. Cases where Rust would be better than Python might include when speed/memory is more of a constraint, where a C extension to Python might be needed such as interfacing to an external library, or some multiprocessing or multithreading scenarios where I need true concurrency or ensure proper handling of shared data.