←back to thread

517 points bkolobara | 4 comments | | HN request time: 0.001s | source
Show context
BinaryIgor ◴[] No.45042483[source]
Don't most of the benefits just come down to using a statically typed and thus compiled language? Be it Java, Go or C++; TypeScript is trickier, because it compiles to JavaScript and inherits some issues, but it's still fine.

I know that Rust provides some additional compile-time checks because of its stricter type system, but it doesn't come for free - it's harder to learn and arguably to read

replies(17): >>45042692 #>>45043045 #>>45043105 #>>45043148 #>>45043241 #>>45043589 #>>45044559 #>>45045202 #>>45045331 #>>45046496 #>>45047159 #>>45047203 #>>45047415 #>>45048640 #>>45048825 #>>45049254 #>>45050991 #
ViewTrick1002 ◴[] No.45042692[source]
Neither Go, Java or C++ would catch that concurrency bug.
replies(2): >>45043212 #>>45050050 #
1. Const-me ◴[] No.45043212[source]
C# would catch the bug at compile time, just like Rust.

https://www.rocksolidknowledge.com/articles/locking-asyncawa...

replies(2): >>45044178 #>>45046051 #
2. notfed ◴[] No.45044178[source]
It's almost as if this post was written in direct response to TFA to brag about how far ahead C# has been for over a decade.
replies(1): >>45050301 #
3. IshKebab ◴[] No.45046051[source]
I don't know C# but it looks like they added a specific check just for locks, which is far less powerful than Rust's Send/Sync.
4. tialaramex ◴[] No.45050301[source]
The C# is basically showing the Monitor pattern, which was also a thing in Java last century.

The Rust Mutex is an Owning Mutex which is a different feature whose benefit is that you need to take the lock to get at the protected data, which averts situations where you forget in some code but not others and create sync problems - in C# those may go undetected or may trigger a runtime exception, no guarantees.

But perhaps even more importantly, and why other languages which could do the Owning Mutex often do not, Rust's borrow checking means the compiler will spot mistakes where you gave back the lock but retained access to the data it was protecting. So you're protected both ways - you can't forget to take the lock, and you also can't give it back without also giving back the access.

Monitors prevent only the second (and only partly), an Owning Mutex in most languages prevents the first, but Rust prevents both.