Should you learn rust and men? Yes, yes you must
Languages that offer details
When most people start programming, they are attracted to languages that make things easy. Python and JavaScript and other high -level languages strip the chaotic details of memory management, system calls and hardware interaction. This abstraction is strong – it allows beginners to create useful programs quickly without being involved in the implementation details.
But there is a great value in the languages that force you to face these details. Languages like RUST, C and Zig not only making you a better programmer in those specific languages - they deepen your understanding of how computers already work. This understanding makes you more effective in every language you use, and even high -level linguistic.
To clarify, let’s take a “simple” concept such as reading the user’s entry and storing it into a variable, then explain how it will be done from upper to low languages. We will start with all of them all:
Bethon
name = input("What is your name?\n")
print(name) #Ah, the classic I/O example
For the learner, what can be questions and learn here? Remember, we are not just trying to get out of the code, but in reality we have an idea of what is happening:
-
Variables and memory: We have “variables” that contain data.
-
Types of data and memory: We have data types, and chains are simply an ordinary text. A very curious learner can learn about other types of data from this idea.
-
Job calls: We can call the jobs with the media and store the results of these jobs in a variable.
-
Operation time environment Python software can be run by calling the translator translator and with the program (assuming that we have installed Python; I will not raise the bear which is the Python version, dependencies, and installation). This can lead to a discovery on translated languages VS.
This is not bad. I think the biggest knowledge of computers will come from that small “\ n” in the series. Explore this a little from this would lead to ASCII and UTF-8 and represent the text in the computer. Maybe it will be also A lot for beginners, but it will give them an idea How the text goes to 0S and 1s. There is also a small lesson on interpreters and translators here, but that requires a great excavation.
JavaScript/Typescript (Node)
import readline from 'readline/promises';
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const name = await rl.question('What is your name?\n');
rl.close();
console.log(name);
//Oh, js, so horribly wonderful in your ways
In addition to the previous visions, let’s evaluate what the strange learner can notice simply exploring this symbol:
-
Input/output flowsWe see explicit signs to Stdin and Stdout. Simple exploration may lead to stdin and stdout files in UNIX environments, and perhaps even file descriptions and “everything is a file” in Linux systems.
-
Operations: vision practical The object can lead to a curious person to know the operations and gain a glimpse of the implementation process of modern operating systems. Although they may not get it completely, they now have an idea.
-
Unstable i/o.:
await
The promises made the learner to how to deal with incomplete computers, and perhaps even a question about the reason why they did not implement them directly (such as Python). This driving to learn:-
Concurrent and non -simultaneous implementation, I/O is not banned, and perhaps synchronous
-
Promises, Microtass waiting menu, task waiting list, and programming that depends on events and its benefits.
-
-
Establishing interface and resource management: The creation and closure of the interface leads to the question and gain an understanding of resource management, especially for important resources such as input/output flows.
-
Keywords advertisement ((
let
andconst
): This does not explicitly plan to deeper concepts, but it teaches good practices to control change. -
Operating time environment: JS programs are operated through operating time, knots, gate, Deno, etc. The task of operation is to save V8 (JS) with additional features to make it a full language. Perhaps one can ask What Exactly these times the V8 engine provides, this would lead to I/O ASYNC applications.
Some of these, like promises and menus, are JS’s abstracts at first glance, but if a person finally finds his way to Libuv – The Caire Canties that deal with I/O Self for Node.js – they will learn a little about I/O in operating systems.
C-SARP
Console.WriteLine("What is your name?");
string? name = Console.ReadLine();
Console.WriteLine(name); //Surprise!! No public static void Main(string[] args)
The usual suspects in the character coding are here, despite being blocked ReadLine
and WriteLine
Besides these, two important things come:
- Fixed writing and explicit types: Although the type of reasoning is a great advantage of productivity, I maintain the opinion that the types of writing explicitly improve the learning process, especially for beginners. Here, the learner can get the first real idea of memory planning, especially as it explores the reasons for explicitly identifying variables. These include a specific byte charges of some variables and errors that occur when trying to fit 64 by 32 bytes of memory.
- Incalous types: They learn that the memory site can have no valid value, which increases the promotion of memory width.
- A curious person will really start the question – why do we have to express frankly the championship types? Are there any specific problems that stem from the treatment of empty values as not super values in the programs? This leads to the knowledge of memory protection rules.
-
The time to run the common language (ClR), intermediate language (IL), and JIT: The operating time .NET makes the assembly more clear by forcing the learner explicitly BuildAnd then Run The symbol.
Forcing the user to assemble their code allows them to see IL created. This gives us our first view of assembly (false assembly, in any case), instructions, and records. There is also a possibility to learn about the CLR assembly in a timely manner if the learner wears a little further under the cap.
While these concepts are present in other languages, the difference is that exposing them to the user allows them to immediately excel in a deeper way and gain an idea of what truly It occurs to run the symbol.
finally, I/o Most extracted here from JS. We do not have anything related to currents and resource management.
Golang
Sorry, Groups, but I cannot cover Everything, Or that this article will become very long.
Rust
use std::io;
fn main() {
println!("What is your name?");
let mut name = String::new();
io::stdin()
.read_line(&mut name)
.expect("Failed to read line");
println!("{}", name);
}
//Almost a 1:1 from The Book
To a moderate curious learner, what can be understood about the concepts of the system:
- Explicit ability:
mut
The keywords display the variables are not subject to virtual change. Again, control data exchange for all its benefits.
- Treating explicit errors:
.expect()
He explains that the input/output can fail and force the error in mind. This is taken as a Muslim by almost higher languages, and the learner can understand that interacting with physical devices can lead to a set of errors that one may not think if they are not presented. For example, try to ask the database developer if the tablets are perfect.
- Direct access to the current:
io::stdin()
It explicitly reveals the interaction with I/O resources at the OS level. Just as it was before, this allows the deepest diving in I/O concepts in the operating system, and the difference here is that things are more naked than they were in JS.
- Customize memory:
String::new()
Our first confrontation, albeit continues, appears with the pile and stack, and they are one of the most important concepts in memory. Although it is not very clear, it gives enough idea that the strange learner may start easily in exploring memory and asking questions like – “Why do we need different memory areas?” “What is the pile?” etc.
- References and borrowing:
&mut name
It reveals our first explicit introduction Indicators. Although every language so far has used the references under the cover, exposing it in front of it in front of the programmer allows them to start getting deeper ideas to plan memory. They learn that we can use the same data in multiple areas through the use of references, as well as the benefits and risks of such an approach.
-
Compounds, executives, and assembly: Once again, it is necessary to explicitly require a constructive step for the learner to start exploring the assembly process, but this time, they have an opportunity to see the assembly instructions, and a little about the process of implementing modern central processing units.
Even if you are comfortable with high -level abstraction, the experience of a small rust ingredient can illuminate a whole world of system behavior that is still hidden in other languages. Most of these things are not new, so, the difference is that here, they are exposed to the programmer, forcing them to think and get to know them. This brings more general expenses and difficulty, but this is rewarded with deeper understanding and thus, the strength on the regime resources.
winding
const std = @import("std");
pub fn main() !void {
var debugAllocator = std.heap.DebugAllocator(.{}).init;
defer std.debug.assert(debugAllocator.deinit() == .ok);
const allocator = debugAllocator.allocator();
const stdout = std.io.getStdOut().writer();
const stdin = std.io.getStdIn().reader();
var name = std.ArrayList(u8).init(allocator);
defer name.deinit();
try stdout.print("What is your name?\n", .{});
try stdin.streamUntilDelimiter(name.writer(), '\n', null);
try stdout.print("{s}\n", .{name.items});
}
//lol, the code block doesn't have support for Zig
Note: I truly Discuss whether or not a “growing” “growing” chains should be included, or simply obtaining a very large, specialized “fixed” chain, but since I used a “developmentable” chains for each other example, we are here. To simply explain, the growing chain can grow with an additional input, while the fixed chain is fixed – the only way to add new letters is to create a new letter with the new letter.
Boy, where do we start? If the learner has to look at this symbol, they are likely to be afraid and escape, but what can be learned about the concepts of the system by exploring this:
- Debate and memory: Zig explains that when we need to get a memory from the pile, we need to announce our intentions to do so; This is not just as it is as in rust. Here, I put naked. Although this adds more initial public expenditures, it demands the developer to start exploring the stack, pile, dynamic memory and Syscalls and why we need even explicitly allocate and memory. This enhances the developer’s understanding of the memory structure.
- Detection of cleaning and leakage: Clear
defer
Calls to clean memory and checks for memory leaks are good starting points to learn problems that arise from the incorrectly managed memory. At this stage, the developer is equipped enough to go deeply on this topic.
- Series, slides and references: The chains are simply indications of a group of
u8
Values. This removes the last part of the abstraction between the concept of high -level “chain” and the “low -level” group of the idea of the house.
- Direct access to input/output flows: Again, by making these things visible, the developer understands what It is happening When they read or write from I/O outside the program.
- I/o errors and errors: Input/output devices – and Syscalls in general can fail. The developer must explore this and be aware of that.
C and C ++
I think you are getting the point that I explained here; There is no need to overcome a dead horse.
So, there is going. A simple task in multiple languages. I hope you are convinced of my point. Before we go, let’s explain some things:
So, just write a rewriting in rust?
No, the answer is no – just no. I prepare these arguments from the perspective of a person who wants to learn more about how computers and the person who needs to press everything from your devices (you can also go to assembly, like players in FFMPEG so, if you want).
But what happens when you are fine with some efficiency sacrifice for the speed of development? What if you need to write a lightweight web server with some logic in a day or two? What happens when you are a new developer that this C ++ scares to the point that they want to drop the symbol?
There are a lot of situations that there is something like Go, Elixir, Haskell, or anything well. I just ask that after that, you take some time and learn a little about what is really going on; You don’t have to be a low -level scale that can write ASM in their sleep, but know what is happening with computers will Help you write better, more performance code. This will help you stop seeing your computer as a black box. I also promise you that you will enjoy it.
Talk to me on Twitter.