Rust from a JavaScript perspective

submited by
Style Pass
2021-06-08 22:00:06

I’ve been having a lot of fun using Rust for writing small tools. My day to day work involves a ton of JavaScript and Rust provides a familiar feeling, so trying out Rust was an easy decision to make. But at the same time, actually doing meaningful work in Rust requires a lot of rethinking on how to structure and reason about your code. The compiler – true to its call – is merciless; yet, for some reason, it emerges quite a pleasure in tinkering your code to make it so that it – finally! – compiles.

In this post, I am documenting – albeit in a bit funny way – some thoughts in my journey so far in Rust land, coming from the viewpoint of a hardcore JavaScript enthusiast.

Modern Rust *appears* pretty similar to modern JavaScript. You declare your variables with let, your functions look pretty similar, types aren’t a stranger because of TypeScript , there’s async/await and overall it exhumes a sense of familiarity.

Unfortunately, the good news section ends pretty fast.  The core of the issue isn’t  syntax, but the way Rust reasons about the internals of your program. In high-level languages, you get cushy abstractions that shield you from the way computers work. And that makes perfect sense; if your goal is to commute to your workplace, you just need to know how to drive the car  – you don’t have to fiddle with the internals of its combustion engine. In contrast, on low-level languages you get the bolts and screws and you have to be a car mechanics to drive to the grocery store.

Leave a Comment