Rust is Hard

I’m not a Rust expert by any means, but I’ve spent enough time with the language that I can write reasonable code with a bit of effort (and a lot of DuckDuckGo). However, I’ve found that I often hesitate to use it for my personal projects.

Rust is a large language. The sheer number of features and their complexity introduce so much cognitive overhead while writing code that I can’t always muster up the mental energy to use it for things I’m simply tinkering around with after work. It’s just not possible for me to keep the whole thing in my head.

If I was writing Rust for my day job, it would be a different matter. Using it to build production software every day would let me internalize it to the point that it would become mostly automatic. It would let me cement difficult concepts in my brain so that I wouldn’t have to go looking for explanations every five minutes (lifetimes, anyone?)

Sadly I only get to use Rust for one-off side-projects, which means I spend maybe two hours a week using it. This gives me barely enough time to get my code into a working state, let alone dive into things like the Rustonomicon or even macros.

I love Rust, so I’m going to continue using it despite my issues with it. I’ll just have to lower my expectations of the level of proficiency I can hope to attain with the language.

PS: somebody please give me a Rust job 😭

Week of 2 November, 2020

  • Biden won! This is great news not just for America, but the entire world. It’s a ray of hope for those of us who have been disillusioned the democratic process in recent years.
  • Now if only we could get rid of our own knock-off version of the Orange Man. Sadly, we have to endure until 2024 before we get a chance to vote him out.
  • In more good news, I finished the first part of Crafting Interpreters! I used Python for my implementation, which you can find here. Next step: do it all over again in Rust 🦀
  • The medication I was initially prescribed for anxiety had been working well for me until three weeks ago, when it inexplicably started giving me brain fog and putting me to sleep for most of the day. I was put a different medication last week, and this one makes me wired. Fun. Funfunfun.
  • Since I wrote my last weeknote, I’ve really gotten into Emacs. Like, really really really gotten into Emacs. Besides programming, I’m now using it to read RSS, take notes, keep a journal, manage files, and read email. I’ll maybe possibly probably write a longer post about this later.
  • Even though this has been a terrible year for musicians, a surprisingly large number of good albums were still released. My favorites so far are RTJ4, SAWAYAMA, how i’m feeling now, Saint Cloud, BOSS, and Ultra Mono. There’s still a few weeks to go before the end of the year, so I’ll probably end up expanding this list pretty soon.

Rust: Structuring and handling errors in 2020 (from Nick Groenen)

Everything I’ve built with Rust so far has been tiny in both scope and size, so writing out my error handling code by hand hasn’t been much of a hassle. However, I’ve been meaning to look into some of the popular error handling crates so I don’t have to write a ton of boilerplate every time I want to introduce a new type of error in my applications.

Nick Groenen covers two such crates in his blog post on error handling in Rust: https://nick.groenen.me/posts/rust-error-handling/

This reddit thread has further suggestions: https://www.reddit.com/r/rust/comments/gj8inf/rust_structuring_and_handling_errors_in_2020/

im

im is a library that implements immutable data structures for Rust. It works with serde so you can make your data persistent. Consider pairing this with Druid.

Week of 13 April, 2020

  • The cats have stopped fighting! Minor squabbles still break out once or twice a day, but for the most part they’ve settled into an uneasy truce.
  • Found a contract for the next six weeks. It’s not a Rust gig as I had hoped, but it involves some heavyweight data visualization in the browser that will call for a lot of cleverness. I expect to enjoy this thoroughly.
  • Eating a lot of cheese this week. No regrets.
  • Working through Crafting Interpreters at a decent pace, though I could probably be going faster. Instead of just translating the Java code in the book, I’m trying to write idiomatic Rust as far as possible. This takes longer and makes my design totally different from what’s in the book, but I’m learning far more this way. I’ve also added a few additional features to my implementation, like proper line editing in the REPL using rustyline.
  • My fitness trainer now has an online lesson plan, so I’m back to working out. Feels good to be doing something with this bag of meat.
  • Still irritated at how much pointless detail that Gandhi book has. But I’m going to get through this thing one way or another.
  • Still playing Radiant Historia and Into the Breach, still loving the hell out of both games.
  • Album highlight of the week is Cha Cha Palace by Angelica Garcia.

The Expression Problem

While reading Crafting Interpreters, I learned about something called the expression problem. It’s a problem I’ve run into countless times, especially in larger projects, but I never knew it had an actual name. As usual, Eli Bendersky has an in-depth article about the problem and its solution in C++ and Clojure.

After reading Eli’s article, I wondered how the problem would manifest in Rust and what the solution would be. Turns out it’s not too complicated. Want to add a new type? Just add it and implement all the traits you care about. Want to add a new operation? Define a new trait and implement it on all the types you care about. This article goes into more detail on what that looks like.

Week of April 6, 2020

  • Spent a lot of time on calls with potential clients. Happy to report that I can sound very professional even when I’m not wearing pants.
  • Started reading Crafting Interpreters. With a lot more Rust under my belt than the last time I tried this, things are going better than I expected. I even managed to add reasonable (by my standards) error handling to my baby interpreter!
  • Started posting things on this blog again, trying to keep it fun and low-stakes. I want to have fun writing, and turns out Growing an Audience™ and Using Fully-Formed Sentences™ is the exact opposite of fun.
  • Played a lot of Radiant Historia on the 3DS. I’m loving the gameplay and story so far, but the combat needs to get more interesting soon.
  • Played a few hours of Into the Breach on the Switch. Holy. Fucking. Shit. This is easily one of the best designed video games I’ve ever played. I see myself pouring many many hours into this gem!
  • We got a new kitten just before pandemic, hoping that she’d become friends with our older cat. Did not go according to plan. It’s impossible to leave them in the same room together without one of them trying to murder the other every five minutes. We’re keeping them separate for now, hoping for at least an uncomfortable truce.
  • The first half of Gandhi: The Years that Changed the World was incredible, but now the book is getting repetitive. It has a lot of detail that I consider unnecessary. I’m somehow powering through the last 200 pages so I can pick up Ursula K. Le Guin’s Earthsea series.
  • Some albums I enjoyed this week were: Saint Cloud by Waxahatchee, 2017-2019 by Against All Logic, and Aarupa by Quinton Barnes.