issue157:c_c
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue157:c_c [2020/05/31 09:26] – créée d52fr | issue157:c_c [2020/06/05 14:20] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | https:// | + | **https:// |
Okay rustafarians, | Okay rustafarians, | ||
- | In this issue, we will quickly go over data types, as each programming language has its own way of dealing with things like booleans, etcetera. | + | In this issue, we will quickly go over data types, as each programming language has its own way of dealing with things like booleans, etcetera.** |
+ | |||
+ | https:// | ||
+ | |||
+ | OK, bandes de RUST-iques, nous revenons au développement de Rust car @Daredevil14 et Ellin se sont plaints de la direction que prenait le blog de Lucas sur Rust. Il semblerait que vous aimeriez toujours plus de rust et moins de non-sens sur la sécurité. En premier lieu, ne négligez pas la lecture du livre ci-dessus. Si vous êtes complètement débutant dans rust ou même en programmation, | ||
+ | |||
+ | Dans ce numéro, nous passerons rapidement sur les types de données, car chaque langage de programmation a sa propre façon de traiter les choses comme des booléens, etc. | ||
+ | |||
+ | |||
+ | **Let’s start with those while we are at it? Booleans in Rust are called ‘bool’. As in other programming languages, it is used in things like loops. However, if you have been following Greg’s excellent Python tutorial, you will know Python uses a capital T for True and a capital F for False. This is not the case with rust. You simply refer to them as ‘true’ or ‘false’. Characters are referenced by ‘char’. A character is always in single quotes and strings are in double quotes. This is a common newbie error as “a” and ‘a’ are NOT the same type. For numbers you need to know integers and floats. I have no doubt that if you have been following Greg, that you know what they are. I must point out, as we learned in the first part, there are ways to refer to them. Obviously, we have signed and unsigned integers, to represent negative numbers. This affects the size of the number you can use, as they take up a certain amount of space in bytes. You refer to signed | ||
- | Let’s start with those while we are at it? Booleans in Rust are called ‘bool’. As in other programming languages, it is used in things like loops. However, if you have been following Greg’s | + | Commençons avec eux pendant que nous y sommes ! Les Booléens dans Rust sont appelés « bool ». Comme dans les autres langages de programmation, ils sont utilisés dans des choses comme les boucles. Cependant, si vous suivez l'excellent |
- | The way the numbering works is for example, i8 refers to; one byte for the sign, plus seven (7) bytes for the number. 1, | + | **The way the numbering works is for example, i8 refers to; one byte for the sign, plus seven (7) bytes for the number. 1, |
The same with floats or floating point numbers. It’s ‘sane’ default is f64.Just keep it in mind when you are on a 32-bit machine, like a raspberry pi. | The same with floats or floating point numbers. It’s ‘sane’ default is f64.Just keep it in mind when you are on a 32-bit machine, like a raspberry pi. | ||
Ligne 15: | Ligne 24: | ||
Why did the programmer quit his job? .... He didn’t get arrays (a raise - geddit?) | Why did the programmer quit his job? .... He didn’t get arrays (a raise - geddit?) | ||
- | OK, I’ll see myself out... | + | OK, I’ll see myself out...** |
- | What is an array? This is a ‘list’ of things, that are all the same type, grouped together. What I mean by this, is that an array does not mix say, strings and numbers. You can not have an array with a key, sword, a shield and the number 250 that represents your gold. If you want to have your salad mixed, you use a tuple. (We will get to it now.) The format for an array in rust is: | + | La numération fonctionne par exemple de cette façon : i8 fait référence à un octet pour le signe plus 7 (sept) octets pour le nombre. 1, |
+ | |||
+ | Même chose avec les « floats » ou nombres décimaux. La valeur par défaut « sûre » est f64. Gardez-le juste à l' | ||
+ | |||
+ | Maintenant, un peu plus compliqué. | ||
+ | |||
+ | Pourquoi le programmeur a quitté son boulot ?... Il n'a pas compris les tableaux (arrays) (il n'a pas reçu une augmentation, | ||
+ | |||
+ | Bon, d' | ||
+ | |||
+ | **What is an array? This is a ‘list’ of things, that are all the same type, grouped together. What I mean by this, is that an array does not mix say, strings and numbers. You can not have an array with a key, sword, a shield and the number 250 that represents your gold. If you want to have your salad mixed, you use a tuple. (We will get to it now.) The format for an array in rust is: | ||
let < | let < | ||
Ligne 26: | Ligne 45: | ||
< | < | ||
- | NOTE: I use the word “position” here, but feel free to substitute it with “index” as newbies find it easier to make the connection that way. | + | NOTE: I use the word “position” here, but feel free to substitute it with “index” as newbies find it easier to make the connection that way.** |
- | A word on this, make sure of your position or index before changing it, as it overwrites the previous value. | + | Qu' |
+ | let < | ||
+ | |||
+ | Pour accéder à un des éléments d'un tableau, le format est : | ||
+ | let < | ||
+ | |||
+ | Ce qui suit nous montre aussi comment modifier un tableau : | ||
+ | < | ||
+ | |||
+ | NOTE : j' | ||
+ | |||
+ | **A word on this, make sure of your position or index before changing it, as it overwrites the previous value. | ||
To change an array, like the previous issue, we need the ‘mut’ keyword otherwise they are immutable. This ‘mut’ keyword may take some getting used to. | To change an array, like the previous issue, we need the ‘mut’ keyword otherwise they are immutable. This ‘mut’ keyword may take some getting used to. | ||
Ligne 42: | Ligne 72: | ||
cargo new --bin lesson2 | cargo new --bin lesson2 | ||
- | Again, this will make what you need. | + | Again, this will make what you need.** |
- | Remove the “hello world” and replace it with the code shown top right. | + | Un mot à ce sujet : vérifiez la position ou l' |
+ | |||
+ | Pour modifier un tableau, comme dans le numéro précédent, | ||
+ | |||
+ | Comme pour les entiers, les tableaux possèdent une taille fixe quand il sont créés. | ||
+ | |||
+ | Essayons-le ! | ||
+ | |||
+ | Naviguez jusqu' | ||
+ | |||
+ | saisissez : | ||
+ | |||
+ | cargo new --bin lesson2 | ||
+ | |||
+ | Une fois encore, ce dont vous avez besoin sera fait. | ||
+ | |||
+ | **Remove the “hello world” and replace it with the code shown top right. | ||
Type: | Type: | ||
Ligne 54: | Ligne 100: | ||
How now, brown cow? | How now, brown cow? | ||
- | Rust suggests we use a vec. With vec’s we push and pop our elements. (More on this later.) By-the-way, at any time you want to know more about something, you can look it up by searching the phrase on doc.rustlang.org – try it: https:// | + | Rust suggests we use a vec. With vec’s we push and pop our elements. (More on this later.) By-the-way, at any time you want to know more about something, you can look it up by searching the phrase on doc.rustlang.org – try it: https:// |
- | During the quick once-over on arrays, I mentioned tuples. Again, if you have been following Greg’s Python tutorial, you may know where this is going. A tuple is a collection of things, like an array, but they do not have to be of the same type. (Like an array, indexing starts at 0) The following code is valid: | + | Enlevez le « hello world » et remplacez-le avec le code présenté en haut à droite. |
+ | |||
+ | Saisissez : | ||
+ | |||
+ | cargo build | ||
+ | |||
+ | Que s' | ||
+ | |||
+ | Et maintenant, mon vieux ? | ||
+ | |||
+ | Rust suggère d' | ||
+ | |||
+ | **During the quick once-over on arrays, I mentioned tuples. Again, if you have been following Greg’s Python tutorial, you may know where this is going. A tuple is a collection of things, like an array, but they do not have to be of the same type. (Like an array, indexing starts at 0) The following code is valid: | ||
Let mytuple = (donkey, true, 99); | Let mytuple = (donkey, true, 99); | ||
Ligne 70: | Ligne 128: | ||
You can even grab the lot at once, simply by: | You can even grab the lot at once, simply by: | ||
- | let (weapon, | + | let (weapon, |
- | Rust is smart enough to plug in donkey to weapon, true to armour and 99 to gold. Now you can keep your gold in your inventory with that extra shield and sword! (or donkey, *wink* it is your inventory after all) | + | Pendant le rapide passage sur les tableaux j'ai mentionné les tuples. Là encore, si vous suivez les tutoriels de Greg sur Python, vous pouvez savoir ce qu'il en est. Un tuple est une collection de choses, comme un tableau, mais qui n'ont pas l' |
+ | |||
+ | let montuple = (âne, true, 99); | ||
+ | |||
+ | Pour faire référence à un élément d'un tuple, nous utilisons une syntaxe légèrement différente de celle d'un tableau. Le format est : | ||
+ | |||
+ | let < | ||
+ | |||
+ | Dans le cas du dessus, pour obtenir 99, nous aurions dit : | ||
+ | |||
+ | let x = montuple.2; | ||
+ | |||
+ | nous pouvons même traiter l' | ||
+ | |||
+ | let (arme, | ||
+ | |||
+ | **Rust is smart enough to plug in donkey to weapon, true to armour and 99 to gold. Now you can keep your gold in your inventory with that extra shield and sword! (or donkey, *wink* it is your inventory after all) | ||
Go ahead and try the guessing game in the book: | Go ahead and try the guessing game in the book: | ||
https:// | https:// | ||
- | Yes, I know it’s a boring example that sucks the marrow from your bones, but it teaches important concepts! | + | Yes, I know it’s a boring example that sucks the marrow from your bones, but it teaches important concepts!** |
- | 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 it’s own terminal! All nicely in one place. | + | Rust est assez fûté pour mettre âne dans arme, true dans armure et 99 dans fortune. Maintenant, vous pouvez garder votre or dans vos biens avec cette protection et cette épée supplémentaires ! (ou votre âne ; *clin d' |
+ | |||
+ | Allez plus avant et essayez le jeu de devinettes dans le livre : | ||
+ | https:// | ||
+ | |||
+ | Oui, je sais, c'est un exemple ennuyeux qui suce la moelle des os, mais il vous apprend des concepts importants ! | ||
+ | |||
+ | **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 it’s own terminal! All nicely in one place. | ||
If you have any questions or comments, e-mail us: | If you have any questions or comments, e-mail us: | ||
- | misc@fullcirclemagazine.org | + | misc@fullcirclemagazine.org** |
+ | |||
+ | La raison pour laquelle j' | ||
+ | |||
+ | Si vous avez des questions ou des commentaires, |
issue157/c_c.1590909960.txt.gz · Dernière modification : 2020/05/31 09:26 de d52fr