My impressions of Rust after coding with it for two weeks

My friend is tired of me going on and on about Rust, so I thought I'd talk your ears off instead.

I've started coding in the language two weeks ago, although have dabbled in it by reading the first 10 or so chapters of the book a while before that. I usually take a rather pragmatic view to coding: a programming language is something that's meant to get the job done, basta! But not with Rust. Something about the language just makes coding fun and makes me want to perfect my code. I think that's a combination of many tiny things that Rust just got right that makes it more suited to writing structured code that expresses the coder's intent more than other languages.

So I tried to articulate what I find good in Rust, and some things I found lacking during my first two weeks of programming in it.

positives

  • sane defaults like privacy rules; lack of customization actually helps not agonize over choices
  • in general the language design is very coherent and when I learn something it's not just yet another piece of syntax (C++, I'm looking at you)
  • being able to split impl across multiple files; I'm sick of monstrous classes in Python and C++
  • amazing ecosystem: formatter and cargo are god-sent, clippy as well
  • a copy of Rust's many books and the whole documentation is included for offline access in rustup's installations
  • Integrated Testing! Before using Rust, I never tested my code so thoroughly, and I could do this from day 1; not adding tests to my code is now unthinkable
  • superb learning material
  • everything is an expression; because of this, coding Rust feels like my thoughts just flow right out of my fingertips
  • Error Handling!!!! I cannot stress enough just how much I abhor throw and catch in other languages, and that was way before I even knew about Rust
  • rayon is amazing; the first thing that comes to my mind when improving performance is now if I can parallelize my code; before that wouldn't have even crossed my mind
  • I don't know why, but all in all Rust just lends itself to writing beautiful code; when I'm done writing something in Rust, it's something I can show; compared to when I write something in C++, which in mild terms, is going to be a complete mess; and I'm only a beginner!
  • Last but not least, the amazing community! With the two issues I've posted on this forum, I immediately got multiple expert answers with lots of patience despite my obvious struggling with basic concepts

And Rust's main promise, the memory safety, isn't even on this list. Not that it's not incredible. But in all honesty, I found all these small but very noticeable improvements a much more important selling point of the language.

negatives

  • slow hashing, I think there should be a std::collections::HashMapInsecure; it's nice to have a safe default, but I don't want to jump through hoops when I just require a quick HashMap, and this use case is actually quite common, so it would be nice if it was an opt-in like unsafe
  • no way to handle OOM failure; although I don't plan writing any applications like that in the near future, it's kind of a bummer that Rust just aborts on OOM
  • in my opinion, unchecked indexing is too cumbersome; I get that Rust is focused on safety and that one should first profile their code before optimizing prematurely, but I wager to say that no one really knows how much performance is lost due to Rust's index checks, even if many checks can be optimized away

wishes:

  • Rust on GPUs, specifically CUDA
  • it's hard to use packages offline; it would be nice if there was a version of rustup that shipped with some most used crates (rayon, criterion, indicator, rand, ...), like conda for Python

I hope this post is suited for this forum. I just felt like sharing my experiences. :slight_smile:

2 Likes

You can use fxhash or hashbrown for faster hashmaps (hashbrown now backs the std, but the crate itself has different defaults).

This is being worked on in the allocators working group

3 Likes

As I think, if you use iterators instead of indices, Rust will optimize away most of those checks

4 Likes

I've seen fxhash and some other hashing crates and actually needed to use a custom hashing function. I didn't know about hashbrown though. That seems perfect for when you don't have any custom needs and just want a fast HashMap. I'll keep that in mind!

I've looked at the github for the OOM failure (https://github.com/rust-lang/rust/issues/43596). Looks fairly quiet, the last response was 28 days ago. Not that I particularly need it, it just kind of bothers me that a language like Rust simply crashes on OOM. At least someone wants to work on it.

I know and I love iterators, so I try to use them as often as possible. But a lot of algorithms can only be expressed with indexing. Either that, or I'm simply too inexperienced with iterators. It's probably not a concern when you're just doing "standard" programming though.

It's true that you can lose performance by indexes. I got a small-ish speedup in a programming competition in the Algorithms and Datastructures course I took last semester by defining a custom Vec type that doesn't do them. But the thing is that allowing non-unsafe unchecked indexes is simply completely against the basic principles behind the language, and I definitely think it is worth it.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.