3 ms·
The main thing of Rust that Java can’t provide even after Valhalla is compile time thread safety guarantees. I find those in the meantime one of the biggest ad
by Matthias247 5y ago
The main thing of Rust that Java can’t provide even after Valhalla is compile time thread safety guarantees. I find those in the meantime one of the biggest advantages of using Rust - and miss it in all other programming languages. Questions like „can I refactor this code to make it parallel und use the database client / IO stream / etc from multiple threads simply answer themselves.
Apartment from that I think the type system power of Java/Kotlin in the near future is good enough and a nice blend of complexity and getting things done. And with Valhalla, Loom and modern GCs a lot of performance concerns should also be removed
- kaba0 5y agoRust can only guarantee that no data race will happen. Other race conditions are still possible, so I don’t really see Rust that much safer than Java. Concurrency is hard everywhere.
- charleslmunger 5y agoIndeed. I recommend using tsan for java. https://wiki.openjdk.java.net/display/tsan/Main https://wiki.openjdk.java.net/display/tsan/Main But the types of races I struggle with in java I suspect are similarly hard in Rust. Here's two pieces of concurrent code I struggled with: https://github.com/google/guava/blob/master/guava/src/com/google/common/util/concurrent/ExecutionSequencer.java#L286 https://github.com/google/guava/blob/master/guava/src/com/go... https://github.com/google/guava/blob/master/guava/src/com/google/common/util/concurrent/SequentialExecutor.java#L162 https://github.com/google/guava/blob/master/guava/src/com/go... I'm not sure reasoning about the correctness of those would be easier in Rust, but if there are any rust experts reading this I'd love your perspective.
- kaba0 5y agoThanks, I haven’t seen tsan before. Java also has JML but I don’t know how much does it help regarding concurrency.
- Matthias247 5y agoInteresting - didn’t knew tsan is now available for Java. Which JDK version is it available for? The linked wiki isn’t super clear on this. But given it seems a 2020 Addition I guess only for rather recent ones.
- Matthias247 5y agoWhile that is the only guarantee it can provide - in practice it ends up being a lot more powerful. Eg most multithreading issues in Java occur due to totally missing synchronization - because developers either didn’t think about threads or didn’t have enough experience to apply correct synchronization. In Rust the compiler would already have complained about these cases, and eg the design of the Mutex type - which wraps data instead of standing next to it - makes it hard to abuse.