logoalt Hacker News

wakawaka28yesterday at 1:49 PM1 replyview on HN

>In those languages, correct logic and getting the program to compile doesn't guarantee you are free from data races or segmentation faults.

I don't believe that it's guaranteed in Rust either, despite much marketing to the contrary. It just doesn't sound appealing to say "somewhat reduces many common problems" lol

>Also, Rust's type system being so strong, it allows you to encode so many invariants that it makes implementing the correct logic easier (although not simpler).

C++ has a strong type system too, probably fancier than Rust's or at least similar. Most people do not want to write complex type system constraints. I'm guessing that at most 25% of C++ codebases at most use complex templates with recursive templates, traits, concepts, `requires`, etc.


Replies

simonaskyesterday at 4:29 PM

Comparing type systems is difficult, but the general experience is that it is significantly easier to encode logic invariants in Rust than in C++.

Some of the things you can do, often with a wild amount of boilerplate (tagged unions, niches, etc.), and some of the things are fundamentally impossible (movable non-null owning references).

C++ templates are more powerful than Rust generics, but the available tools in Rust are more sophisticated.

show 2 replies