← Back to context

Comment by 90s_dev

1 year ago

> and you can even locally reason about the code much better than in typical 'unsafe' languages like C++.

Do you have an example of this? I'm just a TypeScript guy who never had a fair chance to use C++ or Rust for long, so I'd be curious how what you say is true.

One of the strongest example for me is newtypes. I strongly believe in Parse, don't validate (https://news.ycombinator.com/item?id=21476261) and think Rust's newtype pattern is able to really enforce this strongly.

When writing a Rust program, I can often basically express it as a single value (the input) being sequentially converted in type. The typestates, if you choose this name, allow great compile-time verification of most desired properties. You are really forced to describe the way the core logic flows in a modular way.

However this is just one and likely not even the most prominent aspect making Rust so great. Local reasoning also becomes easier via explicit opt-in mutability, and function signatures always being the only relevant source of truth when regarding their compile-time evaluatability (especially compared to C++ templates). No accessing uninitialized memory, a very simple implied notion of a constructor as merely a method without a self parameter, soundness of all received types, likely much more...