Uk News

Should you learn Rust and Zig? Yes, yes you should do

Languages ​​that reveal the details

When most people start programming, they are drawn to languages ​​that make things easier. Python, JavaScript and other senior languages, memory management, system calls and scattered details of hardware interaction. This abstraction is strong – beginners should create useful programs quickly without making swamps in the application details.

However, there is an important value in the languages ​​that force you to face these details. Languages ​​such as Rust, C and Zig do not only make you a better programmer in these certain languages, but also deepen your understanding of how computers actually work. This understanding makes you more effective in every language you use, even in senior languages.

To display, let’s get a “simple özel concept such as reading the user’s input and storing it in a variable, then show how to make it to lower levels from higher levels. We will start with the highest level of all:

Python

name = input("What is your name?\n")
print(name) #Ah, the classic I/O example

Questions and learning for a student what could be here? Remember, we are not just trying to make the code crank, we have an idea about what actually happened:

  • Variables and memory: There are “variables olmak that holds the data.

  • Data types and memory: We have data types and strings are only normal text. A very curious student can even learn other data types from this clue.

  • Function calls: We can search for functions with independent variables and store the results of these functions in a variable.

  • Working time environment Python programs can be operated by calling the interpreter and the program (assuming that we install Python, I will not poke the bear with Python version, addictions and installation). This can lead to a discovery in interpreted vs compiled languages.

These are not bad; I think the biggest information about computers will come from that little ‘\ n in the string. Discovering a little bit about this will lead to ascıı, UTF-8 and the text to be represented as bytes on the computer. It would probably be more A lot for beginners, but to them idea How the text went to 0 and 1s. There is also a small lesson about interpreters and compiler, but this will require significant digging.

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 information, let’s evaluate what a curious student can observe from discovering this code:

  • Entry/Output Streams: We see clear references. Stin and Stdout. A simple discovery of these is the ‘Everything File’ in UNIX -based environments to Stin and Stdout file streams and even file identifiers and Linux Systems.

  • Processes: To see Process The object can trigger a curious person to learn processes and take a look at the execution process for modern operating systems. Even though they don’t get exactly, now idea.

  • Simple G/Ç: await And promises offer the student a question about how the computers handle them immediately uninterrupted operations, and even why not only (such as Python). This learning driving:

    • Synchronous and simultaneous execution, non -blocking G/ç and maybe simultaneousness

    • Promises, microtas tail and task on the node, event -oriented programming and benefits.

  • Interface Creating and Resource Management: The creation and closure of an interface leads to inquiry and understanding about resource management for important resources such as G/Ç Flows.

  • Declaration Keywords (letconst): They do not clearly match with deeper concepts, but they teach good practices to control change.

  • Working Time Environment: JS programs are a working time, knot, bun, deno, etc. Is operated through. To ensure the work of working time. V8 (JS motor) To make a complete language with extra features. Maybe questionable What Exactly this operating time provides the V8 motor, which will lead to simultaneous I/O applications.

Some of these are abstractions about JS at first glance, such as promises and queues, but if one person finally finds their way Libuv – They will learn some about G/Ç in the C library – operating systems that operate simultaneously for Node.js.

C-SHARP

Console.WriteLine("What is your name?");
string? name = Console.ReadLine();
Console.WriteLine(name); //Surprise!! No public static void Main(string[] args)

The usual suspects of character coding, albeit here, ReadLine And WriteLineIn addition, two important things emerge:

  • Static Writing and Open Types: Although species inference is a great feature for productivity, I maintain the view that writing types clearly improve the learning process, especially for beginners. Here, a student can gain the first real memory order ideas, especially as they discover the reasons for clearly identifying variable types. These include the reservation of specific byte counts for specific variables and errors that occur when you try to fit in 64 bytes 32 byte -Bayt memory.
  • Nullable Types: They learn that a memory position is not possible to have a valid value and that it is possible to increase the memory appearance further.
  • A really curious person will begin to ask – why should we clearly state the species of Nullable? Are there certain problems arising from taking Null values ​​as non -Null values ​​in programs? This leads to learning memory protection rules.
  • Common Language Work Time (CLR), Middle Language (IL) and JIT: The .NET working time makes the compilation process more pronounced by forcing the student clearly to force them clearly. buildand then to run code.

Forcing a user to compile codes allows them to see the created IL. This allows our first view of the assembly (so -called assembly, nevertheless), instructions and records. In addition, if a student is withdrawn a little further further, there is also the potential to obtain information about the compilation of CLR in time.

Although these concepts are present in other languages, the difference is that exposing them to the user will immediately go deeper and gain an idea about what. Really Runs the code.

Finally, G/Ç is more abstracted than JS. We have nothing about flows and resource management.

Golag

I’m sorry, Gophers, but I can’t cover it everything, Or this article will be too 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

For a moderately curious student, what can be understood about system concepts:

  • Open changeability: mut The keyword indicates that variables are invariable as default. Again, check on the change of data for all its benefits.
  • Open error processing: .expect() Indicates that G/Ç may fail and force the error. This is almost higher in languages, and a student can understand that interaction with physical devices can lead to a series of errors that may not think that they are not prominent. For example, try to ask a database developer if the discs are perfect.
  • Direct flow access: io::stdin() OS level clearly demonstrates its interaction with G/Ç resources. As before, this provides a deeper diving to the concepts of G/Ç in an operating system, the difference here is that the jobs are much more naked than JS.
  • Memory allocation: String::new() Although the first, so -called open, it encounters a mass of stacks and a lot of of the most important concepts in memory. Although not very clear, the curious student can easily discover memory and “Why do we need different memory zones?” Gives a clue that he can ask questions such as. “What is a heap?” and so on.
  • References and borrowing: &mut name It reveals our first open entrance pointer. Although each language has used references under the hood so far, exposure to the programmer to the programmer allows them to gain deeper ideas about the memory order. They learn that we can use the same data in more than one region by using only references with the benefits and hazards of such an approach.
  • Compilers, Executive Products and Assembly: Once again, once again causes the student to start discovering the compilation process once again, but this time, the chance to explore the assembly instructions and the chances of modern CPUs have a little chance to see the execution process.

Even if you are comfortable with high -level abstractions, trying with a small element in the cake can illuminate the world of system behavior that remains hidden in other languages. Most of them are not new, so the difference is that they are exposed to the programmer here, forcing them to think and learn. This brings extra load and difficulty, but this is a deeper understanding and consequently rewarded with the power on the resources of the system.

Peak

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

NOTES: I Really He discussed whether he would include a heap -all -all -all -all -all -all -all -all -all -allocated ‘static’ strings, but for all other examples, ‘growth’ strings, we are here because I use strings. Simply explained, while a string can grow with an extra input, a static string is corrected – the only way to add new characters is to create a new character with the new character.

Oh son, where do we start? If a student was to look at this code, they would probably be afraid and escaped, but they would be able to learn about the concepts of system by discovering it:

  • Allocates and memory: Zig explains to us that we need to declare our intentions to do this when we need to get memory from the heap; This is not like a pass for us. He was left naked here. This encourages the developer to clearly allocate the developer, and why we need to allocate the developer and even free memory. This further strengthens the developer’s understanding of memory structure.
  • Cleaning and leak detection: Open defer Controls for memory cleaning calls and memory leaks are good starting points to learn from the first -hand problems caused by improperly managed memory. At this point, the developer is really equipped to go deep in this regard.
  • String, slices and references: The strings are simply pointers for a series. u8 values. This eliminates the last abstraction between the high -level ‘string’ concept and the low -level ‘byte series’ idea.
  • Direct Access to G/Ç Flows: Again, by making these things visible, what is the developer to be When they read or write from G/E other than the program.
  • G/O errors and error processing: G/O devices calls – and in general, Syscalls may fail. The developer must discover and be aware of it.

C and C ++

I think you understand the point I do here; No need to beat a dead horse.

I mean, you’re going. A simple task in multiple languages. I hope you were convinced of me. Before you go, let’s clarify a few things:

So, just rewrite in rust?

No, the answer is no – just no. I do these arguments from the perspective of someone who wants to learn more about how computers work and all of them from your hardware (if you want, you can go to assembly like men in FFMPEG).

However, what happens when you are good to compromise some efficiency for the sake of development? What if you need to write a light web server with some logic within one or two days? What happens when you want to leave code when you are a new developer that was so frightened by C ++?

There are many situations where go, Elixir, Haskell, or everything that is good. You just take some time after that and learn a little bit about what’s going on in reality; You don’t need to be a low -level buzz that can write ASM in their sleep but know what to happen with computers. will Better helps you write more performance code. And it will help you stop seeing your computer as a black box. I also promise to like it.

Talk to me on Twitter.

Related Articles

Leave a Reply

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

Back to top button