DEV Community

Cover image for My Rust Book: Language for the next 40 years
bolubee101 for Rust Nigeria

Posted on • Edited on

My Rust Book: Language for the next 40 years

Chapter 1: Discovery

My Rust story started when a 17-year-old me found some articles about it on Stack Overflow. Rust had built a bit of a reputation, that prompted me to do some research on it even though I had no use for it at the time.

A bit of a back story. Before Rust, I was working on Byte Stash, a decentralized file system. The plan was to write a Proof of concept in JavaScript, then write the actual program in an ahead-of-time compiled language. The thing is I didn't know what language to use. Of course, C/C++ was the first option that came to mind, but the second thing that came to mind was the possible pitfalls that one could encounter while using it. So, I decided to search for another option.

Whenever I discover a new programming language, there’s this thing I do with it, it’s probably not the best way to judge a language, but when I see a “-.lang” website, I go in and try to reason about the semantics. If I find it intuitive I can say I am already a fan of it, and if I don't find it intuitive then, hehe. That’s the problem I had with Golang and its walrus assignment operator at the time, its use just wasn’t as intuitive to me as I’d have wanted it to be.

That didn’t mean Rust was without qualms. Rust is beautiful, and things make sense as you learn. But in the early learning phase, when writing it, it can be hard to follow. With the static type system, the compile-time optimizations, it’s possible to lose track of what you’re actually working on. When you get the hang of it though, the feeling is ecstatic. In the Rust book, there was this exercise, “12 days of Christmas” I rewrote that particular piece of code over and over again. The aim was to write it in as few lines as possible, eliminating all the default scaffolding code. When I was done, “beautiful” was what I’d describe the end result as. I took a screenshot and kept it on my Whatsapp status for like 3 days (even though I didn’t think anyone cared to see it).

Chapter 2: The Holy grail

Back to why I learnt Rust, byte stash. I put the project aside. Hold on, hear me out. After building the proof of concept in Javascript, my search for the ahead-of-time compiled language for the main project began, then I found Rust. In the time I took to learn rust, and finish up on the proof of concept, I burnt out and took a break from writing code. So I decided to put it aside till I had other people pitch in. Instead, I started rewriting my JS libraries in Rust. Xbyte is one of them. Xbyte was a tool I made to convert bytes into human-readable sizes and vice versa. For instance, 4747 → ('4.75 KB'). When I built this in Javascript, it was relatively easy. But in Rust, it was another ball game. I didn’t need a 64-bit integer, or a 128-bit integer so I invented my 91-bit integer. I spent a lot of time on it, reading what was in the standard library and adapting it to my 91-bit integer. I did abandon it later though and go with the 128-bit integer. But I learnt a lot while working on it. When you are not used to working with core primitives, and you get to touch the holy grail, you feel like you have to advocate for the holy grail. I hadn’t spent much time optimizing for performance previously, but when I started writing Rust, I got to think about optimization, the feeling was exhilarating, a bit frustrating, but definitely exciting. For instance, in javascript, everything is on the heap, you don’t think about it. But with Rust, you are conscious of what you are doing. That’s what I love about Rust. Even if you don’t go to MIT to learn about how computers work, you can’t help but think about some of these things. Not because if you don’t things would go bad, but because these concepts are baked into the type system.

Chapter 3: The expression of knowledge, and possibilities.

In 2019, I scoured YouTube for every video on Rust, watching conferences, and tutorials. At some point, I doubt there was any video content on Rust I had not watched. It was fun. But there is one thing I found out. The more knowledge you have in your artillery, the more you’d be able to express yourself while writing code. As you learn more about a language like Rust, what you can do, how you can do it expands. And it slipped into how I did everything, including writing my documentation.

Around that time, I started working on Freya, a software that would pull all the metadata from various music providers. You paste a link it would grab the metadata of the track, playlist, or album and present it to you so that you'd be able to do anything with it. It was written in Nodejs, but I wanted to write it Rust, or at least create a GUI in Rust. I created a UI component library for it, but didn’t get to using it, I burnt out. But after taking a brief break from coding, I went back to learning Rust. I kept building things, not because I had to, but because it was an idea, and it was possible.

Chapter 4: Near

January 2020, I was on my way to computer village (A place where gadgets could be bought or repaired), when I received an email from a recruiter from Near on LinkedIn who had seen some of what I had been working on and wanted to get more information about me. He explained the whole thing and brought up the issue of work, and I was interested. A couple of interviews were set up, and I did research on who my interviewers were. Guy, one of them was a professor. I started to wonder what I brought to the table. All I had were some CLIs and some libraries. It was later I found out from one of my interviewers that one of the things that drew them was how I wrote my documentation which when I thought about it made sense. I spent a lot of time on the Nodejs documentation, so I wrote mine in a similar way. Near builds and maintains a blockchain, something I had no experience about when I joined. This is something I have to talk about. A lot of people think you have to be a blockchain god to join a blockchain company, well I wasn’t, and neither were a lot of the people who work at Near. We were all just a bunch of good engineers from different fields who would just bring their expertise to the table. The blockchain side of things is just something they picked up when they join.

Chapter 5: Different and good.

At NEAR, one of the things I was excited about was the kind of people I work with. Aleksey Kladov, the author of Rust analyzer, and the person who reviewed his first PR code work at my company. In the time I’ve worked with them, I have come to realize that they both write Rust differently yet, they maintain almost the same level of aesthetically pleasing elegance in their code. Another thing I’ve come to realize is that there are people that have such a deep understanding of how the language works that even before running the code, they know what assembly output would be, how it would work, the possible errors the rust compiler would flag. It’s crazy.

Chapter 6: Change and letting go.

Change is good. At some point in my journey, I realized due to my interests, my language set wasn’t what was going to get me hired. Most people were interested in Backend, Frontend, etc. But building system things was what I was interested in. There were times I just put aside my fascinations to just get the job done, but those experiences were not rewarding. So for me, moving to Rust was the logical thing to do. While I had to learn the language and all, my focus didn’t really change. In my initial days, there were times I wrote Rust like JavaScript, but there were times Rust wouldn’t even let me. I had to have a lot of shifts in my programming paradigms. For instance, as JS devs, we learn a lot about Object-Oriented Programming. But when you start writing Rust, Structs and traits take over. I found that it's harder to leave things you have learnt for new things even if they are more convenient. But dread it, run from it, change still arrives.

Chapter 7: Language for the next 40 years.

Rust really is an amazing language. I bet at some point in the life of any Rust developer the statement, “Rust has taught me to write better X” has been made, where X is any other programming language. The paradigm shift when writing Rust is amazing and its benefits cut across the board. Rust has practically changed my life, and I don’t see myself really writing any other language for the next 40 years the way I see myself writing Rust.

Top comments (0)