Rust isn’t very hard, in my experience

Biscuit's Cookie Algorithms
4 min readOct 7, 2024

--

For the past month, I’ve been using Rust to create a video game. I’m going to rewrite the game in GDScript, probably, but I first used the language because I was intrigued by all the Youtubers talking about Rust being amazing, and acting as if Rust is the greatest thing since sliced bread. I think my take on Rust is a bit different. I haven’t been programing long enough to see for myself just how bad null, or dynamic memory management, can be. Of course I’ve written memory leaks, but that was when I didn’t know anything about dynamic memory management and why we need it. Now I know.

I saw different takes on Rust. Some said that Rust is amazing. Others said that they didn’t like their productivity being cut in half. I was so fascinated, I decided to try it. In fact, if I didn’t get sick of how slow my code was coming along, I would’ve stayed and learned Rust. That’s the first thing I should mention: You won’t be as fast as you would be in Python, or even C++. When I made my first game, I was way closer to where I wanted to be in a month than in Rust. It must’ve taken me weeks to get a simple select screen running, where you could mouse over a few buttons and the text on said buttons would turn yellow. Then again, I wasn’t using Bevy, I was using SDL2-Rust, because I’m a lot more comfortable with SDL2 in C++. Borrowing isn’t that hard, guys. I found it confusing initially, but a video I came across explained it to me well. In Rust, something like

let mut y= 0;
fn use_int(x : mut i32){
x = 5;
}
use_int(y);

Is illegal, because when you called the function, the value of x wasn’t copied, it was completely moved into the function’s scope.

let mut y= 0;
fn use_int(x : &mut i32){
*x = 5;
}
use_int(&mut y);

Now, what did I just do? The ampersand you see there signifies a pointer. Now, don’t fret. Because I can’t copy values directly, and I don’t want to use that random function that copies values, I instead take a reference, or a pointer, to the value I want as an argument, and use that pointer in my function.

I also like how Rust kind of does memory management for you. All memory, either dynamically allocated or not, is deleted when it goes out of scope(unless returned). But, I wouldn’t be the person to ask about dynamic memory allocation in Rust. I barely used it in the game I was making, and had to look up how to even allocate memory on the heap in Rust.

Another thing you’ll like about Rust is the immutability by default. You have to think about when you want to change something, and most of the time, you don’t want to change something. So you make it immutable. Now it can’t be changed.

You’ll also like None and Some, and Results. They’re all cool ways to check if something is or will return null, instead of actually using null and having to check for it, and forgetting to check for it, and getting an error.

Another thing I liked was how easy it was to use external libraries. I simply had to type which ones I wanted in a file, even though installing this one WASM compiler was a bit difficult. You’ll also love the way that Rust has you organize your files. Structs and functions are private by default, again forcing you to think about if you actually want something to be public or private. But the way that you name them is akin to Java, where the struct name and file name must match. But you can put other stuff in there, too, that can be used across files, not like in Java where you get one public class, and that’s it. Another cool thing is that even if you’re addicted to that dot syntax(like dog.bark()), Rust still forces you to split up your data and functions. You have to use the “impl” keyword. I didn’t use this keyword much for dot syntax, since I was writing a procedural program.

Another thing to note is that I didn’t use lazy evaluation much.

Those are pretty much all the things I liked about Rust. There are two things I don’t like about Rust, though, one of which I’ve already mentioned: The slow write times. One time it took me 4 hours of programming to simply move a few variables I had into a struct. This is because those variables were related to initializing SDL2, and Rust screamed at me a lot about borrowing and lifetimes. The other thing I don’t like is the fact that the Rust compiler couldn’t infer most of the time what datatype I wanted, so I had to specify the datatype at write time. This meant that I had to do a lot of searching the documentation(SDL2-Rust’s documentation is great, by the way) and guessing the correct datatype to use.

All in all, Rust is a great language, mostly held back by its slow prototyping. If you want to use Rust, go ahead. Especially if you have used another language in the past, it’s easy to learn. I like many things about Rust, and if my computer were good enough for Bevy, or if I could prototype faster, I could see Rust being my main language.

--

--

Biscuit's Cookie Algorithms

I am a game developer who wants to document the development of his games, and also gather support for them.