Skip to content

Instantly share code, notes, and snippets.

@traviskaufman
Last active September 12, 2016 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save traviskaufman/179982d717c0c4ff0fb386cbf6e52c68 to your computer and use it in GitHub Desktop.
Save traviskaufman/179982d717c0c4ff0fb386cbf6e52c68 to your computer and use it in GitHub Desktop.
Tips for Coming to Rust from Javascript (WIP)

The following are tips I put together which I would have found helpful after coming to rust from Javascript.

NOTE: If you've never used a statically-typed programming language before, I highly recommend checking out Liz Baille's illustrated survival guide presentation from RustConf 2016.

I've been using Javascript both personally and professionally as my primary language. In many cases, even exclusively. However, I actually got my start in systems programming, writing really bad C code for MaxMSP, and it therefore has a special place in my heart.

Rust is like C, but way better. The rust team has essentially taken the complexity of designing a high-level language runtime and pushed it down the compiler. This is insanely impressive, and produces ridiculously incredible results. This is systems programming language with things like traits, generics, very intelligent type inference, and the best macro system I have ever seen. All without the need for a GC or pretty much any run-time overhead. It's my jam right now, and quite possibly my new favorite language (eclipsing the tie I have between JS and Scala).

However, the language is...complex, to put it lightly. It is extremely daunting. The book is incredible and the community is extremely friendly, but I feel the design goals of rust make it so. That being said, there are a few things I've learned so my far in my short yet intense time with rust that I feel would be useful to other JS developers. I'm writing this in hopes that I can open up the language to more JS devs who are looking for a new language.

Enough babeling (see what I did there...sorry), let's go!

Read about ownership

It's really important. I highly recommend you take the time to not just read, but understand, which I personally found kind of tricky. Especially since my systems skills are so damn rusty (thanks, Javascript).

Rc looks useful

Listen to the compiler

This is actually general advice I usually give for developers coming working with a statically-typed languages for the first time.

Rustc has some of the most helpful compiler messages ever. And it has an --explain command which kind of like having a co-worker who's really knowledgeable about the language built into the compiler.

Compiler messages - in any language - can be overwhelming, seem pedantic, and be hard to get used to. However, taking the time to understand what they are telling you, and more importantly why they are telling you it, is imperative to shipping quality code and being able to maintain it over a long period of time. A great place to start is with --explain as it will help you to ensure that you understand why you're getting these messages. But if that fails, take the most important advice below...

Be a part of the community

They're awesome

JS community is vast, we're used to always having all the answers.

Rust community is smaller. Go help build it up to the level the JS community is at.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment