Hi, I'm Daisy

Here is a place for my random musings!

RustFest Paris 2018

I had the good fortune of attending RustFest recently and, thus, it would be very apt to talk about the Rust programming language. I had heard about Rust around a year ago but never looked too deeply into it because it seemed relatively obscure at the time. The Rust conference and workshop has introduced me to the idioms and intricacies of Rust and now my interest has been piqued! I will outline a couple of things about the language and its ecosystem.

Rust is an open-source systems programming language developed at Mozilla. It is meant to have the efficiency and power of a “low level” language but feels like a “high level” one. Rust is a compiled language that uses an ahead-of-time compile model. In fact, the compiler is very friendly and acts like a smart pair programmer at your side at all times that helps you write better code.

Rust comes with a nice package manager called Cargo that helps you install Crates. Crates can be found under the registry at Crates.io. Cargo also comes with a build tool and built-in test runner as well as a built-in document generator. When you build your project in release mode ( cargo build –release ), this signifies that you want to compile your code for production and this will take a lot more time to do but will give you much better optimization in the end.

In terms of syntax, Rust can infer some of the types that we want and so we don’t always have to specify the types. If the compiler cannot guess with certainty, it will tell you during compile time. Something unique in Rust is that variables are immutable by default. Once we declare a variable and set a value, we are not able to change it. We have to specifically say we want it to be mutable with the mut keyword. Moreover, there are two different types of strings in Rust (String and &str) and how they are handled in memory is the main difference. It turns out that strings are actually really complicated and a lot of other programming languages do a lot of magic to hide it’s complication. Rust exposes this complication with strings.

Rust is not really object-oriented and does not have a concept of class or object, but it uses structs. You can use struct to define your data and then make an impl block to implement the behaviour.

For the more advanced topics, it means diving into the fundamental features of Rust that makes it unique. Rust is a language that was designed to eliminate the supposed tradeoff between control and safety. It was built to prevent crashes and eliminate data races (when you have two threads performing at least one write to the same memory location). It does this through its system of ownership and borrowing. Data has an owner and can be borrowed as long as it is given back. Data can be owned by only one thing at a time. As the sole owner of the data, this means that you can confidently change it and it also gives other things a better understanding of who owns it and when it would be deallocated. This is all a static check since Rust apparently has no runtime.

I noticed that Rust had a lot of similarities to Go, but some of the main differences is that it doesn’t have a garbage collector or a runtime (which, from my understanding, means that it runs directly on the CPU). Rust doesn’t have or need garbage collection because of all the safety features in its model and it has less need for a runtime because it doesn’t have garbage collection. There are still endless advanced topics in Rust that I don’t know yet.

Rust is currently not very widespread and still in a pretty nascent phase (many libraries are not even at version 1.0 yet) but I am interested in following along with its progress. I have heard a lot about its open and friendly community and it was also what I experienced firsthand. Everyone was super friendly and helpful.