Understanding Rust - A Systems Programming Language

What is Rust?

Rust is a systems programming language which runs blazing fast, prevents almost all crashes, segfaults and data races. Most people, now, might wonder exactly why do you need another programming language, when we already have a lot of them.

I'll try to explain exactly why.



Safety Vs Control

We have often seen this spectrum where we have C/C++ which has more control of the hardware which it's running on, enabling the developer to optimize the performance by executing finer control over the assembly generated. However, this is not very safe; it's easier to segfault or to cause security bugs like heartbleed.

On the other hand, we have languages like Python, Ruby, and JS where the developer has very little control over what's going on but they are very safe. They can't get segfaults, you can get exceptions but they are pretty contained. And somewhere in the middle, there's Java and a few others which are a good mixture of both, with control over the hardware they run on and vulnerabilities that don't show up much.

Rust is a bit different. Rust doesn't fall in the given spectrum. It gives the developer all the safety and the control.

Specialties of Rust

Well, Rust is a systems programming language like C/C++ but unlike those,  what it gives to the developers is fine grained control over memory allocations. Garbage collector is not required anymore. It has a minimal runtime and it's very close to the bare metal. What it implies is, the developer is guaranteed the performance of the code and also, anyone who knows C/C++ can understand and reason with a Rust code.

Rust runs blazing fast since Rust is a compile language with LLVM as it's back-end and it taps in to a large suite of optimizations. In a lot of areas, Rust can do better than C/C++.

Rust, like JS, Ruby, and Python, is safe by default which means you can't have segfaults, dangling pointers or null pointers .

One of very important features of Rust is it eliminates data races. Nowadays, we have computers with tons of cores and many threads running in parallel but it's really tough to write parallel code. What elimination of data races does is that it simply assures the developer can't write the wrong parallel code.

Two Key concepts which eliminate data races.

Ownership

Variables are moved to new locations, preventing the previous location from using it. There is only every one owner of data!

Borrowing

Owned values can be borrowed in Rust to allow usage for a certain period of time.

In Fedora 25 & 24

You can use  dnf install rust and get started with Rust. Here's the demo program on Fedora 25.



I have created a simple program to print a statement because printing "hello world" is too mainstream.



That's how I execute it and get the the printed message.

Up Next
    Ebook Download
    View all
    Learn
    View all