5 ms·
Rust's type system is more expressive than Java's so you can end up with much nicer to read code with stricter and more obvious invariants. There also tends to
by efaref 7y ago
Rust's type system is more expressive than Java's so you can end up with much nicer to read code with stricter and more obvious invariants. There also tends to be way less of the `EnterpriseJavaBeanFactory`-style code in idiomatic Rust.
- Polyisoprene 7y agoTrolling is fun and all, but I wouldn’t say Rust’s type system that much more advanced than Java’s. The borrow checker definitely helps to catch errors, but I would rate them at basically the same level.
- gameswithgo 7y agoSo, being able to have a value or a reference vs everything always being a reference is a pretty massive difference. Option types instead of nulls is also a pretty large difference. Generics being better from a performance perspective is a large difference too. As well, traits are quite a bit different than classes, but not always in a good way!
- Polyisoprene 7y agoHopefully Java will support proper values regarding inlining and on-stack allocation for non-primitive types soon, but yes option types are a benefit in Rust as long as you’re not using any more advanced reference libraries.
- tene 7y agoCan you explain more about "advanced reference libraries", and how they interfere with the benefits of option types?
- rattray 7y ago> Trolling is fun and all This isn't in keeping with HN's guidelines[0], eg: > Be kind. Don't be snarky. Of course, you may be expressing an unpopular opinion, so your comment may receive downvotes regardless. You may wish to delete and repost without the first clause to more accurately gauge community response. https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- Polyisoprene 7y agoSure, just reflecting on the “There also tends to be way less of the `EnterpriseJavaBeanFactory`-style code in idiomatic Rust.”
- roca 7y agoRust's type system is definitely much more powerful, even ignoring borrowing. Rust's affine (ownership) types add a lot of power. They make it possible for APIs to take ownership of a passed-in object and guarantee no other references to it exist. For example this lets you manually deallocate resources (e.g. close a File), while preserving the invariant that if you have a reference to a File, then it is open. Also, Rust traits and generics are a lot more powerful than anything Java has. For example Rust generics support associated types. E.g. the Iterator trait has an associated type Item: trait Iterator { type Item; ... } You can now write code that's generic over Iterator, and refers to its Item type: fn first<I: Iterator>(iter: I) -> I::Item { iter.next().unwrap() } Toy example, but associated types are really important. Rust traits and generics are more powerful in other ways too. E.g. in Rust you can do anything with a generic type, unlike Java where type erasure means you can't write 'new T' etc.
- roca 7y agoBTW I'm not knocking Java here. Java's simpler type system is actually great for the applications I think Java is good for --- business logic and simple mobile apps, the COBOL of the 21st century. Well, except that Java went ahead and gratuitously complicated their type system with wildcards. That was crazy.
- Polyisoprene 7y agoSure, but generics are available in Java as well and compared to Haskell and similar language I rate Rust as closer to Java.
- jeremysalwen 7y agoRust's generics are much more powerful. You can do type level programming, e.g. : https://docs.rs/peano/1.0.2/peano/ https://docs.rs/peano/1.0.2/peano/ There's an interesting comparison of Rust and Haskell's type system here: https://www.reddit.com/r/rust/comments/4jh8hv/question_about_rust_vs_haskell_type_systems/ https://www.reddit.com/r/rust/comments/4jh8hv/question_about... I guess it's just a matter of opinion about what sorts of differences you think are significant vs not.
- 7y ago