a.lack.of.progress.report

Hobbies, side hustles, pastimes everybody's got them and about 95% are abandoned1. Many of mine can be found on my Github account. I am doing my best to make sure that my game (a.k.a. Totally Not Abandoned Video Game�) is not one of them. Although, if I were to abandon my upcoming very hyped video game it would be in good company.

top.ten.abandoned.side.projects

  1. Kitchen Remodel
  2. Fix my overflowing toilet
  3. Tinder for ducks
  4. A really cool video game I promised myself I would make (not this one)
  5. Learn to play the fiddle
  6. Tinder for bears
  7. A top ten list of abandoned projects

My major problem seems to have been that I have no idea what I am doing2. So I've asked for help, and received the answer of Lazy foo and their wonderful SDL2 Tutorials. Why SDL2? Mostly because I really like understanding material from as low a level as I can, plus masochism. But I am _not_ masochistic enough to actually try and use C++. Not that C++ is a bad language, it just feels dated3. Which is why I decided to take these tutorials and rewrite them in Rust.

make.it.rust

I really like Rust, I mean like really like it, I've started putting it on my sandwiches! Well until I got tetanus. (Well Actually??) Anyway, in the context of game development there are three reasons I like Rust. The first is having to handle pointers. First of all they're pointy and secondly they're everywhere and seem to be easy to miss. With Rust you don't have to worry about releasing pointers. When a piece of memory is out of scope it's gone4.

The second thing I really like about Rust compared to C++, and not just related to game development, is the error handling. Take a look at these examples:

c++.error.example

const result = func();
if( someErrorCheckFunction(result) ) // Even more hidden code
{
 printf( "Oh noes! An error" );
 return 0;
}
else {
   // Do some cool programmer type things
}

rust.error.example

let result = func()?;
// Do some even cooler Rust programmer type things

Way more succinct! Your future non carpal tunnel hands will thank me.

Lastly due to the previous reasons the same C++ code can be written in Rust in significantly less lines. One of the more complicated examples that I copied over from Lazy Foo went from almost 300 lines of code to 80.

everything.is.great.forever

Blog post over, we did it! We won game development. Roll credits... You still here? Okay so not everything about Rust is perfect, it has a notorious learning curve and I found myself fighting the borrow checker like it stole my lunch and then killed my entire family (not cool borrow checker).

One of the things I found the most confusing was the concept of lifetimes. No not the TV channel that airs such great films as The Santa Squad:

Are you done watching? Did you watch the whole thing? Good stuff right?5 Anyway Lifetimes are essentially just a way to make sure memory stays around when you need it. Do you remember how we don't have to manage memory in Rust, well we sometimes have to. The link I linked earlier does a better job of explaining it so I would just read that. What I learned was that in these situations it's good to have someone to help you go through your code. I even made a visual example, I hope you like highly derivative comics!7

Rust lifetimes comic

conclusion

What have we learned? Well I learned that "C++ < Rust" and that while coding Rust make sure you have a someone you can talk to and ask questions. Don't have someone to go to for Rust help? Rust has quite a large community of people that are sure to help you. We also learn that lifetime movies are great and that I should steal, I mean pay homage to more comics in this blog in the future. I hope you like Garfield!

footnotes

1 Uhhh... I'll just fill this footnote in later.
2 When has that ever stopped the white man before, am I right?
3 And not the good kind of dated like when I dated that duck or that bear.
4 Kind of like alzheimer's but in a good way.
5 My record if 15 seconds before I stop watching. Also is that the guy from Quantum Break?... 6
6 No wait that is his brother.
7 xkcd and Cyanide and Happiness.