issue156:c_c
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue156:c_c [2020/04/25 14:17] – auntiee | issue156:c_c [2020/04/28 12:49] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | En cours, ailleurs ! Voici l' | + | **https:// |
+ | |||
+ | Okay then, we head back to Rust development – as Daredevil14 and Ellin complained about where Lucas’ blog went. Rust seems to be getting more popular as time goes by. | ||
+ | |||
+ | Truth be told, I do not like a language where a simple ‘hello world’ is 2Mb(!!), just because “space doesn’t matter”. Okay, my rant over. Regardless, we are going to look at it as the feedback suggests that this is what our readers want. ** | ||
https:// | https:// | ||
- | Okay then, we head back to Rust development – as Daredevil14 and Ellin complained about where Lucas’ | + | Bon ! Allez ! Revenons au développement en Rust, car DareDevil14 et Ellin se sont plaints de ce qu'est devenu le blog de Lucas. Rust semble être de plus en plus populaire au fil du temps. |
- | Truth be told, I do not like a language where a simple | + | À vrai dire, je déteste un langage dans lequel un simple |
- | For everyone who wants to learn more, I will go through installing Rust first, so you can follow along if you like. This article explains how to install Rust in Ubuntu 18.04 (but 19.x should be the same), using the ' | + | **For everyone who wants to learn more, I will go through installing Rust first, so you can follow along if you like. This article explains how to install Rust in Ubuntu 18.04 (but 19.x should be the same), using the ' |
- | If the download is interrupted, | + | If the download is interrupted, |
- | Once it is done, run: | + | Pour tous ceux qui veulent en apprendre plus, je vais d' |
+ | |||
+ | Si le téléchargement s' | ||
+ | |||
+ | **Once it is done, run: | ||
rustc --version | rustc --version | ||
Ligne 21: | Ligne 29: | ||
If you get a reply, all went well. | If you get a reply, all went well. | ||
- | ** At the time of writing, rust is version 1.41.0. If yours differs, that is OK. Just make sure it is a higher number, not a lower one. | + | At the time of writing, rust is version 1.41.0. If yours differs, that is OK. Just make sure it is a higher number, not a lower one. |
- | Look up: “men at work - cargo” in your browser (an ancient Australian band). You will see an image of a plane and a crate. I will be using binary crates, as it is easy for n00bs like you and me. Think of cargo in this way. Delivering crates, containing what you need. Maybe even listen to “Dr Heckyll and Mr Jive”, now that you have looked it up? | + | Look up: “men at work - cargo” in your browser (an ancient Australian band). You will see an image of a plane and a crate. I will be using binary crates, as it is easy for n00bs like you and me. Think of cargo in this way. Delivering crates, containing what you need. Maybe even listen to “Dr Heckyll and Mr Jive”, now that you have looked it up?** |
- | Type: | + | Une fois que c'est fait, lancez : |
+ | |||
+ | rustc --version | ||
+ | (tiret tiret, sans espace) | ||
+ | |||
+ | cargo --version | ||
+ | (tiret tiret, sans espace) | ||
+ | |||
+ | Si vous recevez une réponse, tout s'est bien passé. | ||
+ | |||
+ | Au moment où j' | ||
+ | |||
+ | Cherchez « men at work - cargo » dans votre navigateur (c'est un ancien groupe australien). Vous verrez l' | ||
+ | |||
+ | **Type: | ||
cargo new --bin rustfun | cargo new --bin rustfun | ||
Ligne 35: | Ligne 57: | ||
When you open main.rs in the src folder, you should see a simple ‘hello world’ already in there for you. Before you entered the src folder, you should have seen a cargo.toml -file. You can open this in a text editor or in Geany if you plan on using it as your IDE, or even just cat it out. We can look at all these folders and files a bit later on; for now, I just want to highlight a few things. | When you open main.rs in the src folder, you should see a simple ‘hello world’ already in there for you. Before you entered the src folder, you should have seen a cargo.toml -file. You can open this in a text editor or in Geany if you plan on using it as your IDE, or even just cat it out. We can look at all these folders and files a bit later on; for now, I just want to highlight a few things. | ||
- | The reason I am using Geany as my IDE is it comes with Ubuntu and we don’t need to add things to it to make it work with Rust, and it will gladly work with toml-files without complaint. It even sports its own terminal! All nicely in one place. | + | The reason I am using Geany as my IDE is it comes with Ubuntu and we don’t need to add things to it to make it work with Rust, and it will gladly work with toml-files without complaint. It even sports its own terminal! All nicely in one place.** |
- | Here is what the installation looks like on my machine: | + | Saisissez : |
+ | |||
+ | cargo new --bin rustfun | ||
+ | |||
+ | (L' | ||
+ | |||
+ | Une nouvelle caisse binaire nommée rustfun sera créée (un dossier et les fichiers de structure). | ||
+ | |||
+ | Si vous ouvrez main.rs dans le dossier src, vous devriez voir un simple « hello world » qui a été mis là pour vous. Avant que vous entriez dans le dossier src, vous devriez avoir vu un fichier cargo.toml. Vous pouvez l' | ||
+ | |||
+ | La raison pour laquelle j' | ||
+ | |||
+ | **Here is what the installation looks like on my machine: | ||
Great, now that you have it installed, let’s look at the basics and how rust treats each one. | Great, now that you have it installed, let’s look at the basics and how rust treats each one. | ||
Ligne 45: | Ligne 79: | ||
Like other programming languages, a variable is just a container for a value, regardless of type. In rust, all variables have types (more later). When we program, we simply refer to the variable by name. | Like other programming languages, a variable is just a container for a value, regardless of type. In rust, all variables have types (more later). When we program, we simply refer to the variable by name. | ||
- | Variable assignments in Rust are prefixed by the word “let”. For example: let my_box = 1; Also, when you assign a value to a variable (when you declare it), you cannot change its value (it is immutable). The following WILL give you an error, because of the above reason (shown below). | + | Variable assignments in Rust are prefixed by the word “let”. For example: let my_box = 1; Also, when you assign a value to a variable (when you declare it), you cannot change its value (it is immutable). The following WILL give you an error, because of the above reason (shown below).** |
- | We will cover more later, but for now, just know about this in Rust. The command ‘cargo run’, will simply tell you that it is immutable. Rust is supposed to be error resistant, so it assumes that if you don’t explicitly tell it that a variable can change, it can’t. Okay... How do we do that? With the ‘mut’ keyword, example: let mut my_num = 1; | + | Voici à quoi ça ressemble sur ma machine : |
+ | |||
+ | Bien ! Maintenant qu'il est installé, regardons les bases et comment rust traite chaque point. | ||
+ | |||
+ | Variables | ||
+ | |||
+ | comme dans les autres langages de programmation, | ||
+ | |||
+ | Dans Rust, les affectations aux variables sont préfixées par le mot « let ». Par exemple : let my_box = 1; De plus, quand vous assignez une valeur à une variable (quand vous la déclarez), vous ne pouvez pas changer sa valeur (elle est immuable). Ce qui suit vous DONNERA une erreur, pour la raison ci-dessus (voir ci-dessous). | ||
+ | |||
+ | **We will cover more later, but for now, just know about this in Rust. The command ‘cargo run’, will simply tell you that it is immutable. Rust is supposed to be error resistant, so it assumes that if you don’t explicitly tell it that a variable can change, it can’t. Okay... How do we do that? With the ‘mut’ keyword, example: let mut my_num = 1; | ||
Just by simply adding that “mut”, the error is gone and our program compiles (shown bottom right). | Just by simply adding that “mut”, the error is gone and our program compiles (shown bottom right). | ||
- | Remember I said all variables in Rust have a type? Well, Rust figures out the type in the background for you. This does not mean Rust type-casts your variable sweaty_shopowner as ‘sleazy’, | + | Remember I said all variables in Rust have a type? Well, Rust figures out the type in the background for you. This does not mean Rust type-casts your variable sweaty_shopowner as ‘sleazy’, |
+ | |||
+ | Nous en dirons davantage plus tard, mais, pour le moment, sachez juste ce qui suit sur Rust. La commande « cargo run » vous dira juste qu' | ||
+ | |||
+ | Simplement en ajoutant ce « mut », l' | ||
+ | |||
+ | Vous souvenez-vous que j'ai dit que toutes les variables dans Rust ont un type ? Eh bien, pour vous, Rust indique le type en arrière-plan. Cela ne signifie pas que Rust inscrit en dur le type de votre variable sweaty_shopowner comme « louche », mais plutôt comme une chaîne de caractères (string). Que Rust se trompe ou que vous soyez masochiste, ajoutez simplement un deux-points derrière la variable suivi du type. | ||
- | Example: | + | **Example: |
let my_shoesize: | let my_shoesize: | ||
Ligne 60: | Ligne 110: | ||
Now a quick word on the files and folders. | Now a quick word on the files and folders. | ||
- | Once you build or run your file, you will see a new file named “cargo.lock”. This file is automatically generated from your cargo.toml file. Be sure your details are correct in the cargo.toml file, before building. There will also be a “target” folder created. Inside will be a debug folder with lots of sub-folders. Feel free to peruse these at your leisure. There should also be an executable file with the same name as your project. Run it now to see if your rust program works. Mine does (shown top right). | + | Once you build or run your file, you will see a new file named “cargo.lock”. This file is automatically generated from your cargo.toml file. Be sure your details are correct in the cargo.toml file, before building. There will also be a “target” folder created. Inside will be a debug folder with lots of sub-folders. Feel free to peruse these at your leisure. There should also be an executable file with the same name as your project. Run it now to see if your rust program works. Mine does (shown top right).** |
+ | Exemple : | ||
+ | let my_shoesize: | ||
+ | Pour le prochain numéro, nous passerons à une autre partie de Rust et présenter comment Rust traite, eh bien disons, les boucles / les branchements conditionnels ? (Retrouvez-moi sur Telegram si vous voulez quelque chose d' | ||
- | The code used in this demonstration is shown right. | + | Maintenant un mot rapide sur les fichiers et dossiers. |
+ | |||
+ | Une fois que vous avez compilé ou lancé votre fichier, vous verrez un nouveau fichier appelé « cargo.lock ». Ce fichier est généré automatiquement à partir du fichier cargo.toml. Assurez-vous que vos détails sont corrects dans le fichier cargo.toml, avant de compiler. Un dossier « cible » sera créé aussi. À l' | ||
+ | |||
+ | **The code used in this demonstration is shown right. | ||
Let’s step through it. | Let’s step through it. | ||
Ligne 74: | Ligne 131: | ||
We incremented the variable with 1, the same as num = num +1 | We incremented the variable with 1, the same as num = num +1 | ||
- | Then println!(“”); | + | Then println!(“”); |
+ | |||
+ | Le code utilisé dans cette démonstration est présenté à droite. | ||
+ | |||
+ | Parcourons-le. | ||
+ | |||
+ | Chaque programme en Rust nécessite une fonction main, comme celle-ci : fn main () {} | ||
+ | |||
+ | À l' | ||
+ | |||
+ | Nous avons augmenté la variable de 1 ; c'est pareil que num = num + 1 | ||
+ | |||
+ | Ensuite println!("" | ||
+ | |||
+ | **What you may not know is that {} inside of the print function; it’s a place holder to plug in a value. The value we plug in is outside of the “” and after a comma. In our case, the variable, num (more on format specifiers later). | ||
+ | |||
+ | If you have any questions or comments, e-mail us: misc@fullcirclemagazine.org** | ||
- | What you may not know is that {} inside of the print function; it’s a place holder to plug in a value. The value we plug in is outside of the “” and after a comma. In our case, the variable, num (more on format | + | Ce que vous ne savez peut-être pas, c'est le pourquoi des {} dans la fonction |
- | If you have any questions | + | Si vous avez des questions |
issue156/c_c.1587817066.txt.gz · Dernière modification : 2020/04/25 14:17 de auntiee