Rust: What is that language and why everybody is talking about him?

Hello world, my name is Francisco, fcoterroba on the Internet and today I'll bring you a post talking about a prgoramming language. Rust

In a matter of minutes, you will know what type of language it is, how to get started with it, who is behind it, what it was used for, will be used for and is currently using, its market share, etc. And well, the most important thing, you already know that here we like to program, we will do some simple exercises about said language.

The first contact will be based on everything around it, from the installation of everything necessary to start messing around to the main examples that are usually made in any other common language.

If you like programming, I recommend you go through the programming tag where you can find the more than 5 projects that I have uploaded to date in a multitude of different programming languages, including JavaScript, Swift and, above all, Python.

If I have to emphasize one, I especially liked the Link shortener with graphical interface in Python with a somewhat advanced level in the language.

If you have a lower level, I recommend the first steps in Swift or how to make a calculator in python using the terminal.

Before starting, although later I will explain what it is, I will I recommend visiting a post that I uploaded more than a month ago, in which I explain many of the most used computer terms in our day to day. Since, in this post, you will see words that you probably do not sound a lot. 🤯 You can reed the post here.

I also want to remind you that a few months ago I uploaded a video to my YouTube channel, very interesting, focused on home automation. Specifically, we connect, configure and install a smart light bulb 💡 with which you can change its color, turn it off, turn it on and much more simply by using your mobile phone and/or voice assistants such as Google, Alexa, etc. 👇🏻

Now yes, let's start!

Rust: What is?

Rust is a compiled, general-purpose, multi-paradigm programming language that was started by Mozilla employee Graydon Hoare in 2010.

To this day, the language continues to be developed and maintained by Mozilla in addition to its entire community since it has the Apache 2.0 license or MIT License.

Rust is a safe, concurrent and practical language. It seeks to be a multi-paradigm programming language capable of supporting pure functional, procedural, non-paradigm and even object-oriented programming.

According to Mozilla policy, Rust is developed in a completely open way and they seek constant opinion and contribution from the community.

As a curiosity, in 2020 it was one of the most used programming languages when working with cryptocurrencies and creating nodes for mining.

At the time, they were looking for very fast code that was at the level of C or C++ but without those memory management problems.

The main core of the Firefox browser engine, Servo, is primarily written in Rust taking advantage of the benefits of parallelism, concurrency, and efficient memory management.

It even has its own repository in GitHub.

They also have a pet named Ferris (which is a crab) and the programmers of this language call themselves rustaceans.

He is Ferris.

According to StackOverflow's annual survey, Rust is the most loved language, the least feared, and the 5th with the highest number of programmers interested in learning the language.

In case money is an incentive for you, the average salary for Rust programmers is almost $75K per year (5th highest paid) and $130K if we only include information from the United States.

How do you install the language?

If you use Windows, the easiest option is to download and install the installer provided on the page rustup.rs.

If you are using Linux or any Unix-based system, simply run the following command in the terminal:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

To check the version of rust installed we can use the command:

rustc version

SIMPLE PROGRAMS

Before starting to make our small scripts in Rust, we have to open our favorite code editor (in my case you already know it is VSCodium) and install the official rust-lang extension. It is easy to find, you simply have to write Rust in the plugin searcher and install it

Now yes, let's start with the HELLO WORLD 👋🏻

The first thing we will have to do is create a file with a rust extension, which is .rs

Next, we'll declare a main function, similar to how we do it in Java. At first glance, the syntax seems very similar.

Within this main function, we will use the method to print to screen with println! and remember, the ;

fn main(){
 	println!("Hola mundo! Os saludamos desde la web de fcoterroba");
}

Later, for this to work, we must compile the file from the terminal with rustc and then execute the file that it generates for us.

For the conditions we do not need parentheses, just to check if a number is even or not, it would be a mixture of Python and any other language due to the issue of braces:

fn main(){
 	if 21 % 2 == 0{
        println!("21 es par");
    }else{
        println!("21 NO es par");
    }
}

To create and declare variables, a very similar syntax is used from my point of view to JavaScript since it is: let nombrevariable = valor;

Loops are more similar to Python with the peculiarity that they go with ranges, so they will always be for … in …

To show variables in the prints, we must open and close braces and at the end, after the entire text string, separate with a comma and write the name of the variable that corresponds to each of the braces that we have written

For the example that we want to show the first ten numbers, including the last, it would be something like this:

A simple counter would be something like this:

fn main(){
 	for i in 1..=10 {
        println!("{}",i);
    }
}

To finish, we are going to do things right, we are going to have a single main function and within it we will import the three previous exercises.

The issue of functions, when you have to pass parameters to them, is somewhat more complex because, apart from giving said parameter a name, being such a strongly typed language, it is similar to C++ and you have to dictate the type of value it expects to receive. .

fn saludo(nombre: &str){
    //Esta función es un saludo que funcionará siempre que se le pase un nombre
    println!("Hola mundo! Os saluda {}", nombre);
}

fn par_impar(numero: i32){
    /*
    Esta 
    función
    funciona
    pasándole
    un
    número
    */
    if numero % 2 == 0{
        println!("{} es par", numero);
    }else{
        println!("{} NO es par", numero);
    }
}

fn recordatorio_diezveces(nombre: &str){
    let tope = 10;
    for i in 1..=tope{
        println!("Por {}º vez, mi nombre es: {}",i, nombre);
    }
}

fn main() {
    saludo("fcoterroba");
    par_impar(24);
    recordatorio_diezveces("fcoterroba");
}  

And little more to add guys, I hope you liked it a lot since I loved this first contact with Rust!

Finally, remind you that if you like my content and want to contribute financially (since I don't earn anything from Adsense), you can send me the amount you want for Paypal. Any amount is well received! 🙂

I also hope you have a great week and see you here soon! A greeting and remember to follow me on the networks as TwitterFacebookInstagram, GitHub and LinkedIn. 🤟🏻

sources: Wikipedia, CriptoNoticias, Genbeta, Stack Overflow

Leave a Reply

Your email address will not be published. Required fields are marked *