loading...

How to combat JavaScript fatigue with Rust

gruberb profile image Bastian Gruber ・5 min read

Do you find yourself in any of those thoughts when creating applications with NodeJS?

  • "I for sure need to pick the right npm module to solve this problem, but which one fits best and is getting supported well?"
  • "Uh, my app is growing so big, I have no idea what the difference between user and customer is anymore and which properties they have."
  • "TypeScript will definitely solve my problems!"
  • "Hm, I don't know if this is an error with TypeScript or in the transpiled JavaScript? Or did I just disable the wrong ESLint option?"
  • "Is this all what I will do for the rest of my career?"

Creating JavaScript applications is easy at first but it's getting harder and harder once the application grows. You can wait and hope that any of the big tech companies will solve your problems through TypeScript and other tools. A few years go by and you ask yourself: Is this all? Do I create CRUD application for the next 20 years?

It is sometimes harder to keep up with the latest hype train then actually learning fundamentals. 

NodeJS became a victim of its own success. The market is flooded with developers, every company is using Node in some part of their tech stack. You can say that companies don 't pick it because of it's underlying technology but because they can get cheap labor and feel safe because all the other companies are also using Node, so it must be a good choice.

Meet Rust

You probably know the saying that you should learn Lisp, even if you won't use it, just because the learned mindset will make you a better developer? Instead of learning Lisp to become a better developer, you can learn a language which is actually in use and will improve you as good as Lisp does. Meet Rust. Rust is not the latest hype, but has fundamentals which offer you a wide range of opportunities, even in the long run.

Rust is a systems language, but it's ergonomic syntax empowers the developer after the first struggles.

From a NodeJS perspective, Rust can be used to create web server applications and services. You can write Lambda functions or full fledged applications. Instead of using TypeScript, Rust has a strong build-in Type system. Instead of using ESLint, it ships with the pickiest compiler out there.

The pain you feel in the beginning is different. I call it good pain. Good pain lets you grow as a person (and developer), bad pain just hurts. I would categorize many of the TypeScript and NodeJS pains as bad pain. Not because the tools are bad, but a language which was created in 10 days just gets you so far.

At some point you need to make a personal decision of how your life should look like. Your day to day has a huge impact on your happiness and the well-being of your surroundings. Rust can help you rediscover the joy of programming again.

After you learned Rust, you may think you just replaced tool X with tool Y and end up in the same place. But, there is a difference. Once learned, you can use Rust to create:

  • Games
  • CLI tools
  • Operating Systems
  • Web Services
  • Browser Applications
  • Applications on Embedded Devices

One would say you can cover the whole stack. Rust creates a self feeding system:

  • Developers from C, C++, Java, Kotlin, Python, Ruby and JavaScript flock to the language
  • Rust and its features are getting discussed not only in a web context but in a wide range of scenarios
  • Different areas, perspectives and use cases are getting fed back into the language in an open way

Lets picture a perfect world 5 years from now

You are writing your web service in Rust. Instead of installing five different npm modules which help you cover your mistakes, you are using build-in tools to harden your code base. After the compiler gives you a green light you are 98% sure your application will run safe and fast in the years to come.

But, hold on, you are still sometimes frustrated by the repetitive work environment. But now you mastered a language which you can use to build your own Operating System on the side, you can implement the TCP protocol, you can create Games and join a local game community. You can even create applications for the Browser which are compiled to WASM. If this is not enough, you can get yourself a piece of hardware and run Rust on it.

Node is not gone

NodeJS won't be completely gone, and your skills neither. However you found a great addition and you might just focus on Rust more in the future. Remember, no language survived forever. NodeJS could end up with the same faith as PHP and others. Picking a systems language like Rust gives you strength and opportunities for many years to come.

Should you learn Rust?

From a developers perspective: Yes, definitely. Rust has many unique features which will be copied also to other programming languages (like Ownership in Swift). Learning Rust sharpens your thinking and will make you more considered in your day-to-day language of choice.

From a safety and correctness perspective: You should aim to replace part of your web service with Rust. Start small and see where it leads you. Other companies like NPM, Dropbox and Yelp are doing it and had big success.

Rust for the web is not completely there, but once fully landed, it can not only convert your web services into safe bets. Once mastered, Rust lets you jump up and down the stack, explore Computer Science concepts first hand and build tools in your free time other then the next CRUD application.

So, take the chance and make 2019 the year you learn Rust. Have something in production by Christmas and try to replace part of your services at work in Rust and see if it's successful. Rust will not only let you sleep calmer at weekends, knowing that a rock solid binary is running in production, but the skills you gained let you explore a vast universe of possibilities around technology.

I will help you with that. Follow my series on "Practical Web Development with Rust" and build with me a shiny web application in the next few months.

Posted on by:

gruberb profile

Bastian Gruber

@gruberb

Exploring Rust for the web

Discussion

markdown guide
 

Ok, I'll be the contrarian...

There's a lot of "Rust is awesome" fanboyish opinion here and it's very light on actual reasons WHY rust is better.

Seems also very unlikely that just because something compiles it could be considered stable with anything close to 98% certainty ... Without adequate testing.

Most of the other stuff you can do once you learn rust can also be done with node, or lisp, etc.

Rust may really be the best thing ever, but there's not enough actual substance in this post to prove it's worth learning.

 

Yeah, if you want to learn Rust feel free, it's a great systems language. But I'm struggling to understand how someone who's having problems with ESLint is going to have a great time with the borrow checker.

Rust helps writing secure, stable, high performant, thread-safe code. For most use cases that node is being used for, they don't have a problem that rust solves. Rocket is very cool but unless you need the performance I don't see why you would pay the dev cost to use it over express or asp.net or whatever.

If you want to evangelize rust and create more rustaceans I think you should write more about the things that rust is good at and how it's worked well for you.

 

Hey Will, thanks for this answer!

I don't think "fanboy" is an appropriate term. Especially not in programming languages.

Feel free to click through the refrences (I highlighted my points with links). Especially read through the NPM paper and the rocket talk on Rust.

A 5 minute read is never any substance for anything, but should give you an idea. With the provided links you have enough to read and watch for probably a whole day.

 

I'll look into it, when I have time to look into it. My point simply was that you didn't provide a lot of compelling proof that it's "better" and many of the reasons provided aren't much more than opinion, really :)

That's good to know! Well you should always take your time going through the post and looking through references.

But that's an inspiring point and I will start a series where each post points out a very specific advantage of Rust!

Thanks for the input Will!

 

Enjoyed the post overall and I'm always looking for my next language to learn. Just got done dabbling with Elixir and have been hitting C#/dotnet stuff currently. Rust is something that is always on my radar. Though I do need to poke fun at one comment.

"NodeJS could end up with the same fate as PHP"

A quick google of "how much of the web is PHP" returns this

According to W3Techs' data, PHP is used by 78.9% of all websites with a known server-side programming language. So almost 8 out of every 10 websites that you visit on the Internet are using PHP in some way.

I understand what you mean, but almost 8 out of 10 isn't a bad fate to have as a language!

 

That's very true Chad. It was a provoking article. What I want to deliver is: Companies who build new products choose other languages then PHP (not all of them of course). So the fade of PHP means: Smaller job market, maybe more competitive with lower hourly wage!

 

Great read! I come from Node.js as well and learning Rust in the last months has been amazing. I feel like many new doors that were unaccessible just opened. And using a new language feels so refreshing after years of being only a JS dev. Thanks for sharing! I can relate of what you wrote for sure.

 

Lol, this is just really uncompelling.

In the context of web development, which paragraph here actually highlights a problem with JavaScript that is best solved by using Rust?

Like, what specifically is insufficient about Typescript?

 

It depends on how large and critical the services are you are building for sure!

Once you reach a level where you care about speed, safety and correctness, you will look for options! Rust is one very compelling one!

Besides the other reason I am mentioning! Feel free to bookmark the article and come back in a few years to re evaluate!

 

Interesting, I will start a series which highlights the reason more in depths and shows them vs. others language. Thank you for your input!

For now: Just click through the highlighted texts (links) and see if you like what you see.

Rust is safe, the "safest language out there" through the compiler and the design of the language.

Also, since it's a low level systems language, you can basically create anything you want :)

 
 

I have a very particular reason for avoiding Rust. It seems that you can learn the language and make web servers or toy programs with it, but the ecosystem is very young and contains no learning material for non-experts of the intended field. For instance, if I'm new to Rust and cryptography, well, good luck! Similarly, there are no resources for learning OS-level stuff with Rust, or learning game engine development with Rust, ... you get the idea!

Python, by comparison, is a stark contrast. The amount of educational material available is overwhelming, and so, someone new to Python and, say, penetration testing can pick up a book like Violent Python and learn something other than a new syntax (read: something useful).

Currently, Rust is for absolute experts (mostly in C/C++) with (highly?) specialized domain knowledge who want to explore something better. If you're not that, and you don't want to write web servers in yet another language, well, keep calm and carry on with what you're doing. :)