Learning Rust

2019-09

From the Stacked Overlow annual survey, rust has had consistant high praise. I thought I would look at it as well. After a few months and a few projects, I believe it deserves its praise.

fn main() {
    let width1 = 30;
    let height1 = 50;

    println!(
        "The area of the rectangle is {} square pixels.",
        area(width1, height1)
    );
}

fn area(width: u32, height: u32) -> u32 {
    width * height
}

It has an great community, “The Rust Book” is a great starting place for anyone learning the language. It has a package manager which is built-in to rust called Cargo. It compiles your packages, manages its dependences and upload them. Having common stucture in the package files helps when reviewing an existing package.

Rust’s ownership model has been an experience. It reduces memory-errors during compile-time and no runtime or garbage collector are needed when the program is running. It is also unique in popular programming languages and takes a while to learn and get use to.

Rust doesn’t have pointers (in safe mode) but I found the need to understand pointers to use rust, especially the difference between passed-by-value or passed-by-reference. This tripped me up for a while. I also learned about a how pointers can go wrong, if the pointer is pointing to data that is unreadable (Null pointers), a pointer that points to nothing (Dangling pointer) or dropping the data when it is needed by another pointer (Double free / Null pointer).

If you find Rust interesting, I would recommend what I did:

First, Spend a weekend using Rust on a problem that you were solving in Python. Give up the project because the compiler errors are driving you crazy

Second, Spend a week reading the Rust Book and tell yourself you understand ownership model.

Third, Spend the next weekend using rust on the project again. Get 90% of the way there but give up and vow to never to talk about rust again.

Fourth, Wait two months, when you need to what to avoid C++ and turn to Rust as an alternative

Fifth, Read the Rust book. Take your time and go through each example.

Sixth, Do lots of mini problems. Get a feel for the ownership model. Realize that int,floats act differently than vec,string and box.

Seventh, Do “Too Many Linked Lists” and feel like you know nothing again.

Eighth Write some bigger stuff and complete what ever you set out to do in the fourth step.

Nineth Write a blog article that you survived learning Rust and used it once. Secretly feel insecure about your software skills.

Actually, start at step 5. When you get to step 9 send me a message with the link.