Hacker News new | ask | show | jobs
by hedora 1321 days ago
Not the person you asked, but for me (coming from C++20, with lambdas, async, etc), the big win is that the borrow checker automates away boring PR comments about "you used std::unique_ptr in a non-idiomatic way that is technically safe, and it bleeds memory unsafety into some random API, so write this level N+1 magic instead".

It also checks that all my threaded code is data race free.

On the downside, it's support for safe (in the sense that the compiler checks it) lock free programming is basically non-existent, which means that stuff that would be easy in C++ ends up being in Rust unsafe blocks that you need a PhD in type theory to reason about.

2 comments

  > On the downside, it's support for safe (in the sense that the compiler checks it) lock free programming is basically non-existent, which means that stuff that would be easy in C++ ends up being in Rust unsafe blocks that you need a PhD in type theory to reason about.
I'm not familiar with the C++ built-in facilities for lock-free stuff (but learning about them currently)

Could you expand on this if you're willing, maybe with some pseudocode?

I've also been curious about things like cache alignment, aligned memory, and false-sharing size detection in Rust -- all of which C++ has as std built-ins

Rust has atomic types that rely on interior mutability. No unsafe blocks are needed for those.