Rust: A systems programming language

by Eduardo Ismael García Pérez — @eduardo_gpg

Translation by Mario García — @mariogmd

Rust logo

So many months ago I was searching for “new” programming languages, those that are getting popular, I found a particular one, Rust.

At first it caught my attention because of its name; ¿Rust? In english refers to any film or coating on metal caused by oxidation, what an unfriendly name, I thought. I found out a little more about it, and then, I left it in oblivion.

After some time I attended a technology event, where I had the opportunity to talk to Brian Anderson, one of the developers of Rust. He explained to me certain things about the language, some fun facts (as why the mascot is a crab?), when we should use Rust, when not, and other things.

With everything he told me, and what I learned that day, I took the decision to learn the language. Now I would like to tell you a little about the language.

About

Rust is a systems programming language developed by the engineers of Mozilla. Rust could be categorized as a new language, as Rust 1.0, the first stable version was released on May 15th, 2015. The latest version today is Rust 1.20, that was released on August 31st, this year.

Rust is a compiled language like C or C++.

Rust is designed so that we can develop software where user interaction almost doesn’t exist. It’s excellent for applications within the client-server model or for internal tasks in our start-up or business. A daemon here or there.

By the way, two operating systems are being developed with this language.

Its syntax is similar to the one of C and C++. Let’s see some examples!

Let’s write the classic “Hello world!”!

fn main() {
println!("Hello world!");
}
Yep, we use semicolons and braces in this language

Now, let’s see a more complex example.

pub fn fibonacci_reccursive(n: i32) -> u64 {
if n < 0 {
panic!("{} Wow, esto es un número negativo!", n);
}
match n {
0 => panic!("Lo sentimos, cero no es un valor válido"),
1 | 2 => 1,
3 => 2,
_ => fibonacci_reccursive(n - 1) + fibonacci_reccursive(n - 2)
}
}

Take a few minutes to analyze the code. If you understand most of the code then you almost have it.

Spoiler: Similar to Ruby, functions will always return the value at the last line of code.

Rust doesn’t have a garbage collector as we have in other languages like Python or Ruby. It doesn’t mean that we, the developers, should take care of the memory use. But don’t worry, we are not alone with this task. Rust makes us write code in the right way. If something went wrong (like declare a variable and never use it, access variables out of their context, etc.), Rust will tell us at the right moment.

Something interesting about Rust, is that variables are immutable by default.

Rust has support for concurrency. Not so many languages are able to work directly with the processor and assign tasks. With this language we can do this in a secure way.

Creation of Threads, sync and access to concurrent data are possible through the use of standard libraries (Rust comes with batteries included).

Similar to Python, Rust comes with its own package manager. This package manager is named Cargo and we can use it to create our projects, use third-party libraries, and so create our own libraries and register them.

It’s easy to contribute to the community.

The community of Rust is growing more and more, as more developers, projects and companies are betting for the language.

Rust in our projects

Rust is designed to be integrated with projects that are in production.

You just need to write (or re-write) in Rust a code block related to a heavy process and then like a gear put it on your project.

For example, there are some Gems that use code written in Rust.

With no doubt, Rust gives us the advantages of a low level language, however, most of the time when we’re writing code, it may feel like we’re programming with a high level language.

I would like to continue talking and showing more Rust code but it would be better that you will experience with the language and learn on your own.

To sum up (as I probably forgot, on purpose, to mention something about Rust) you can see the next video.

Should we learn Rust?

My answer is YES. But only after we have knowledge about other programming languages like C or C++.

If you are new to programming I will suggest that Rust doesn’t be your first language; Its learning curve ain’t easy and you could get some headaches, which could be the reason that you get off the beautiful world of programming.

In the other hand, if you know the basic concepts, take a few hours of the day and use it for learning this language. Start developing your own applications. Maybe, while you’re learning you could find a way to optimize a heavy process or create a new library (the Community will be so thankful).

Here is a link where you can start learning Rust.

My conclusion

Be open to the possibility of learning new things, get out of your comfort zone.

If at the end of the day you find out that Rust is not for you and you want to go back to your preferred language, I could say that you didn’t waste your time and you learned a few things about concurrency and security that could be helpful for your future projects.

PD. Here you can see Ferris, the unofficial mascot of Rust.

Original article in Spanish: Rust el lenguaje de programación