For the last couple of years, I’ve been hearing more and more about a language named Rust. Well known as the most loved language on Stackoverflow’s annual developer survey for the fifth year in a row, Rust is famous for its memory safety without a garbage collector and concurrency without data races! But Rust is also feared as a hard-to-learn language, scaring away many developers. For way too long, I postponed learning Rust. That was a mistake.

Image for post

Most Loved Languages in StackOverflow Developer Survey 2020

You should learn Rust now.

Recently, to further improve parsing performance on large codebases, we started writing Rust at Wildcard. Among all of the languages I’ve tried out, runtime errors such as segfaults, null pointer exceptions, race conditions, etc. are the norm. I took it for granted that being rigorous was the only way to avoid them and that it was the programmer’s responsibility to ensure everything was properly handled. Testing, static analysis, and other methods sure helped but sometimes it still wasn’t enough.

With Rust, most of these runtime errors are converted to compile-time errors, and once code compiles, it works, and for real.

  • There are no segfaults, memory safety is guaranteed at compile time

  • Null doesn’t exist in Rust solving the notorious billion-dollar mistake

  • Data races are programmatically impossible because of the ownership system in Rust!

Image for post

When a rust programmer says it compiles, he means it works

Rust is fast, it’s a systems programming language, meaning memory management is made manually. It is not garbage collected but it doesn’t feel like writing free or delete all over your code. Rust is designed with a simple concept, variable lifetimes: variables are owned by a certain piece of code and are freed when they get out of its scope, very much like local stack variables in C! If the variable is returned by a function, its ownership is moved to the caller, making it possible to outlive the scope of creation.

The core of Rust philosophy is zero cost abstraction: making things as simple as they should be, but without any performance overhead.

Rust is made to be very approachable. I was shocked by the simplicity of the Rust tooling, cargo the rust package manager is amazingly simple and pleasant to use. I’ve never seen a compiler as user friendly as rustc, pointing at the precise location of errors and even suggesting helpful tips! And for the beginners even going all the way and providing an explanation with examples (see rustc --explain), saving us the need to translate compiler errors on stackoverflow!!

#learn #machine learning #python

Why You Should Stop What You’re Doing Right Now and Learn Rust
2.55 GEEK