Blog.

My first time writing Rust

Cover Image for My first time writing Rust
Stan Malinowski
Stan Malinowski

I've recently finished the set of Rustlang tutorials. It was a pleasant experience. I have kept my code in a repository, where each of the tutorial sections has a separate folder.

What I like about Rust

There is a set of things I like about Rust, and about the tutorial. Things I like about Rust

  1. cost free abstractions - when working in JS I sometimes check if it's worth it to use map or for. Nothing like that happens here.
  2. mix of functional and stateful paradigms - I tried both Java and Haskell and can't say I became proficient in both. I enjoyed the elegance of Haskell, but sometimes the chain of functions became too long. OTOH, doing a getter/setter for so many values is so full of boilerplate, I get tired reading that code. I feel Rust's approach keeps the balance at the right level of abstraction - I can do a functional chain of map(|x|x+1).filter().custom_fn(), etc that is 1 abstraction in my mind, and assign it to a variable. My head is not big enough to keep too many processes or too many variables at the same time, Rust has a bit of each.
  3. fn keyword is short and sweet
  4. private fns by default
  5. No priviledged constructor function
  6. clear error messages
  7. tests in code
  8. publishing crates to crates.io is easy

What I like about the Rustlang book

  1. piecemeal delivery of content, does not try to do too much at the same time.
  2. the bits 'around' the code are well cared for. Cargo CLI pacakage manager is used to guide me through creating a new project. This process is repeated a few times. That is convienient for me, as I can remember it better. I remember many troubles with this when learning Java. Starting new project easily is crucial for independent dev experience. In JS create-new-* works for that, but I feel it's less optimized and often not enough. Personal templates are a one way around this, but they need to be updated too. I might do a selection of such templates for myself in the future.
  3. the fact that it's both online and offline - I could easily access the docs
  4. it has convienient navigation with arrows (left and right arrows switch to previous and next section, respectively).
  5. Length - it is longer than 1 tutorial and covers a variety of cases
  6. I was easily onboarded on the 2 usually most tricky at first bits of applications - interfacing with the outside world. Filesystem with io crate and web with http protocol was included in the course, I think it was crucial.
  7. I've never worked with concurrent programs before - only Node async. I was a bit apprehensive, but the tutorials made a good job of making me feel alright there.

What I don't entirely get

  1. modules and imports system - sometimes just didn't work for me

Road ahead

I'll use my newly gained knowledge of Rustlang to use it in V8 WASM. I found Let's Code Minesweeper with Rust and WASM by yishn. Adding another game to my portfolio will be :fire:.