Rust from a Pythonista's perspective


Those of you who have read my first dev log will know that I’m using this game as an excuse to learn Rust. For the last 5 years, I’ve been working with Python professionally and my current job title is: Python Engineer for AI. That being said, I’ve also worked with lots of programming languages to varying degrees (from FORTRAN IV through to things like LabVIEW), so I felt fairly confident going into this that I’d be able to pick things up.

One of the key differences I was looking forward to experiencing was the move away from Object-Oriented Programming (OOP). When I was first introduced to the idea of OOP I was totally confused by how it could be applied to everyday situations I’d come across. Now, I live, breath and think in OOP. Moving to a data-oriented language was going to be biggest challenge in my mind.

After completing the basic hello-world, I quickly set about implementing more complex structures and programs. I really like the Rust Playground as it lets you play around with examples without installing or downloading anything. It definitely helped me learn a lot faster than when I first picked up Python (although to be fair, using a Jupyter Notebook would accomplish a similar thing). By the end of my first week, I had mocked up a simple skill system and combat simulator.

One thing that started to annoy me was the need to explicitly borrow and clone resources. It seemed completely unnecessary and overly complex for what I was trying to achieve. I kept getting compiler errors from statements that looked totally reasonable to me. That is one thing I was beginning to like though, the compiler was normally pretty good at explaining what the error was and pointing out ways to deal with it. This is something that I think most languages should strive for.

When I started to play around with the variety of game engines (I’m not enough of a masochist to write my own engine! yet...) Rust has to offer, things started to change. No longer was the borrow checker a thorn in my side, it was starting to stop me making stupid mistakes. It was preventing me from writing illogical code based on parts of the game engine I hadn’t seen. In short, it stopped me shooting myself in the foot.

One of the ‘quirks’ of a compile at runtime language like Python is that you never know if you’re going to get that odd error when you actually get round to running your program. You add loads of checks and error handling, but there’s always something you miss. However, Rust’s compiler (including the borrow checker) does a pretty awesome job of picking up on the little things. It’s almost like another developer sitting there and reviewing your code before your try to run. Compared to other compilers I’ve used, the error messages in Rust are simply much more detailed and provide a more rounded explanation.

To sum up: Things are going pretty well. Aside from a few minor points where documentation hasn’t kept pace with the code (to be expected from a language still under heavy development), there is little I’ve run into that can’t be fixed with a half an hour’s reading. While I’ve not had to jump onto Reddit and ask for help, looking at the responses on there, I’m confident I’d get help pretty quickly.

Till next time, keep coding!


As a thanks for making it through another devlog, here's a picture of some cats: (not my cats, I don't own cats. But cats are funny)


Get Coffee Break RL

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.