You’re Missing Out If You Don’t Optimize Your Web App with Rust

Written by codesmith.staff | Published 2017/12/01
Tech Story Tags: programming | rustlang | c-programming | c-language | rust

TLDRvia the TL;DR App

“Rust is a secret weapon,” Brian Anderson, software engineer at Mozilla, said in Mozilla’s promotional video. That doesn’t really explain what Rust is and why you’d want to use it in your web application. We’ll demystify Rust by answering some common questions.

Is Rust like Ruby or Python?

Not quite.

Rust, on its face, is a general purpose language that started out as a passion project by Graydon Haore. It’s now an open source project that is flagshipped by Mozilla Research. You can theoretically build anything from a flashy web application to an efficient web server in Rust. Though, what it’s mainly marketed as is a systems programming language, which means that Rust probably will not be competing with Ruby/Rails any time soon.

Rust is more closely tied to C/C++ in that it is a low-level language that is statically typed. What we’re used to as web developers is the dynamic typing that Javascript affords us where strings do not have to be defined as string and integers do not have to be defined as int. Like C/C++, Rust can take full advantage of a machine’s processing power to create systems that are highly performative.

So is Rust C++?

Not quite.

What Rust promises is C++ control without all of the safety issues like segfaults, null pointers, buffer overflows, and many other security nightmares that C++ developers have to wrestle with. Its unique selling point is the checking system that yells out error messages on compilation time, which the aging C++ language does not do. Errors seem like a minor enhancement from the viewpoint of web developers, but for low-level programmers, being warned about improper memory allocation can mean the difference between broken code and production-ready code.

Rust also abstracts out the need for programmers to perform pointer arithmetic and memory management, without the cost of performance speed. It accomplishes this through a concept of ownership explained beautifully in this YouTube video.

Why Would I Want to Use Rust?

Rust is a modular language. Say you wanted to optimize one aspect of your web app written in JavaScript. Instead of diving into C++, you can use an intermediary language like asm.js to compile Rust code alongside your JavaScript code. Because Rust code is safe, you wouldn’t have to worry about introducing app-crashing bugs into your program.

As modern developers, we’re used to the open source ecosystems that popular package manager tools like npm, rubygems, and pypi afford us. Rust comes with a tool called Cargo that allows you to import libraries just as you would by typing an npm install command.

Final Words

Rust promises safe code that runs concurrently, just like many other high-level languages. At the same time, its blazing speed borrows from C-like languages. All told, the hybrid nature of the language makes it a versatile tool to have handy if native optimization tricks and add-ons just aren’t doing the trick.

Side note: Geregely Nemeth combines Rust and Cargo to show Node developers how to integrate the Rust programming language with Node. If you’re still skeptical, read his post and you’ll see how simple it is to embed Rust into your app.

Raji Ayinla | rajiayinla858@gmail.com


Published by HackerNoon on 2017/12/01