Why Should You Learn Rust?

It’s like driving a stick shift

Jacob Kendrick
Mar 10 · 5 min read
Think of learning Rust as conquering this dragon. Photo by Laith Abushaar on Unsplash

Disclaimer: I am no expert on the Rust programming language. I’m merely a proponent of it — an advocate if you will.


Rust, the language

One of the big things is how Rust handles memory. In languages like C, C++ or D, you have to handle memory yourself. As a human, you’re prone to errors, but Rust takes this away from you. The need to manually allocate and free memory is freed from the developer and abstracted into a system of checks and balances within the language. These checks and balances that I refer to is the system of ownership that Rust enforces.


Ownership

If you’re coming from languages like C or C++, Rust’s ownership takes some getting used to. But it’s worth the time that it takes to understand it.

For an example of ownership, take this code snippet:

fn main() {
let x = String::from("Hello!");
let y = x; // This transfers ownership of the String to variable 'y'
{
let z = &y; // This borrows the value of 'y' and returns it when the value goes out of scope
} // End of scope
}

Let’s take a look at what’s happening here. For starters, the variable x is assigned a string type that’s constructed from String::from("Hello!") . Then, another variable is created and assigned the value of x, transferring ownership of the String to y.

The interesting part comes when we create a new scope. We create a variable z and assign to it a reference to variable y. Since y owns x, the value of x is referenced in z. When variable z goes out of scope, its value is dropped and the reference is returned to variable y. This is Rust’s borrow checking in action.

Ownership shines because it enables the programmer to worry less about tracking usage of memory within the program, while simultaneously providing greater efficiency at run-time.


Long-Term Viability

Let’s look at what makes a language viable in the long-term. Some of the biggest things are community support, enterprise support, and package — crate, in Rust’s case — ecosystem.

At present, which of these does Rust have going for it? There’s a plethora of community supported crates on crates.io and more are added every day. Personally, I’ve used crates like Tokio, Serde, and Rocket. All of which make my life easier when it comes to developing applications in Rust. With that in mind, I can confidently say that Rust certainly has the community support going for it.

If it has the community, what about the enterprise? Well, every day, more and more companies join the list of enterprises that have, in some way or another, used Rust within their empires. This is good news, but enterprise support is definitely not all that strong just yet. Despite my sentiment on this topic, enterprise support is definitely growing, it just isn’t where it could be.

The ecosystem is similar to community support, which is very much there. It’s right where it should be and continues to grow with every passing day. The Rust ecosystem is in a perfect spot and it’s only getting better.


Comparisons

Rust versus C

Does Rust do anything C does not or vice versa?

The answer is complicated. Suffice it to say that each has its advantages. However, Rust certainly carries more water with its features than C does, with its bare-bones approach to development and with everything being laid into the programmer’s lap. Rust has the advantage here: A lot of problems that C puts in programmers’ hands are abstracted away in Rust, to the point where it minimally impacts performance. But it also gives the programmer some much-needed convenience.

Rust versus C++

Does Rust do anything that C++ does not do or vice versa?

Again, the answer is complicated, but so is C++. The problem with this comparison is this — think of a tool belt; it follows its wearer around and it contains most of what one might need to properly construct a tool shed. Now, think of a toolshed. That shed might contain everything one could possibly need for any problem that’s ever emerged in the history of humanity. It’s a mixed bag of tools, most of which you’ll never use.

Think of C++ as the shed.

Rust versus Java/C#

Does Rust do anything they don’t?

Not really, although it depends on the programmer and it depends on what you’re planning to do with each of these languages. C# and Java are both compiled languages with runtimes. These languages have garbage collectors and they operate on a virtual machine.

Rust, on the other hand, operates at a system level, operating over the operating system’s basic APIs. This means that you have a lot less overhead but you also have a lot less room for error. The fact that Rust has no garbage collection or runtime means that the developer has more work to do in the short-term.


Conclusion

Because Rust is safe. Rust’s memory safety guarantees that you never have to worry about SegFaults or anything of the sort. It means that the programmer is free to care about their work without having to worry that they’re making a mistake in their management of memory.

If you would like to learn Rust, I will leave the following useful links here for you to visit.

Thank you!


Resources

Better Programming

Advice for programmers.

Jacob Kendrick

Written by

I code. Therefore I am.

Better Programming

Advice for programmers.

More From Medium

More from Better Programming

More from Better Programming

More from Better Programming

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade