How to Stick with Rust

pancy

Pan Chasinga

Posted on August 9, 2020

How to Stick with Rust

Put Your Trust in Rust

For a while, I did not get what the hype about Rust was all about. To me, the language appeared opaque and overly verbose. I had tried a few times to learn Rust, every time giving up for some other priorities that came up.

When I joined Recurse Center, during orientation when the new "recursers" lined up introduce themselves and what they wanted to do there (Recurse Center is a curriculum-less bootcamp), I said I wanted to learn Rust. It was my first attempt out of several ones down the road.

In my opinion, a great language must gives incremental jolts of success to the programmer, however inexperience. It must allows a programmer to write quick crappy programs and run. It must grows with the programmer.

I believe most programmers who aren't successful learning Rust because they don't anticipate a peak learning curve right from the start. Rust is a special language because it actually introduces genuinely new features in decades. Therefore it requires a considerable overhaul of the mental frame which appears to be a barrier to learning for some.

Believe it or not, once you get through the peak learning curve, which should last roughly around a month or two (at least for me), it goes downhill from there. The language turns into a productivity engine that is flexible enough to grow with the programmer. It allows you to write quick crappy program that doesn't suck at all (And I'd argue that when your worst code is already fine, there's only room for better).

I've been writing Rust for my startup for the last few months, and here is a few tips I think will help newcomers ease into making Rust stick:

Avoid using &str

Against popular opinions, I'd advocate trying to avoid using &str (and effectively lifetime annotations) at first. Of course, it won't be possible all the time, but it keeps the first few dips pleasant. You might be allocating much heap memory with String and clones, but chances are your program still run much faster than a Python counterpart.

Learn modules

Rust Modules are a source of frustration to many. But it's not much to grok and worth the time to get it out of the way at first.

Use crates

Rust is super modular and very easy to put crates together to build meaningful applications, due to the superb cargo cli that is comparable to npm. Using external crates is a great way to get more done without going into the nitty gritty detail at first. Crates with friendly APIs and docs can go a long, long way.

Focus on building, not learning

If your goal is to learn Rust, you will likely fail because the return on investment is too low. That was how I failed a couple of times before. Think of a reasonably-sized project you'd have built with another language, and fixate on using Rust instead. Here are some ideas:

  • Command line tool
  • API Server
  • Game

Take the compiler seriously

What's really unique about Rust is its helpful compiler messages. This alone had made 60% of my success. Many great languages with really obscure errors. Rust compiler almost teaches you. It reveals how much care the language designers put into making the user experience. We all make more mistakes than success, and we should learn from each of them.

Use cargo check

Rust is notoriously slow at compiling, and that can kill your fire. Try to run cargo check on your code before running it to save some time.

Don't give up

Don't give up and hop onto learning another shiny language. While there are a plethora of "cool" new ones out there to learn, nothing gets close to the balance Rust has to offer.

💖 💪 🙅 🚩
pancy
Pan Chasinga

Posted on August 9, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Using Struct
learning Using Struct

July 30, 2024

Functions in Rust
learning Functions in Rust

July 16, 2024

Method Syntax
learning Method Syntax

July 30, 2024

SORRY, RUST & DEVS !
rust SORRY, RUST & DEVS !

March 29, 2024