3 ms·
Isn't Rust's type system mostly about not having GC? What specific type system features are you looking for outside of borrow checking? Macros? Probably the cl
by nvm0n2 3y ago
Isn't Rust's type system mostly about not having GC? What specific type system features are you looking for outside of borrow checking? Macros?
Probably the closest would be Kotlin. It has the huge JVM ecosystem, it uses GC, programs run fast, they can be compiled to native binaries using at least two different native compilers (kotlin/native and graalvm). The type system is fairly expressive, albeit not quite as much as TypeScript. It makes up for it with just being a much cleaner and more logical language in general, as it didn't inherit much historical baggage.
There's also a compiler plugin API which is maybe the closest equivalent of macros. It's not really documented or stable in Kotlin 1.x, they're fixing that for Kotlin 2, but there are already a bunch of useful plugins that add various features via compile-time generation and reflection.
- masklinn 3y ago> Isn't Rust's type system mostly about not having GC? What specific type system features are you looking for outside of borrow checking? Sun types, affine types, traits.
- veber-alex 3y ago> Isn't Rust's type system mostly about not having GC? What specific type system features are you looking for outside of borrow checking? Macros? 1. ADTs with exhaustive pattern matching 2. No exceptions 3. Zero cost generics 4. Traits 5. No nulls 6. No inheritance
- fweimer 3y agoRust has exceptions. They are used throughout the standard libraries to report some errors, and as far as I can tell, they are deeply ingrained into the default testing framework. As a rule of thumb, languages that loudly claim not to have exceptions actually use them in some way (see POSIX C, Perl, Go).
- TwentyPosts 3y agoSaying that Rust "has exceptions" is dishonest. What matters isn't whether they technically exist, but if and how they're used. In idiomatically written Rust you will never obtain an exception/panic (unless there is a bug), and exceptions are not used for control flow. This is not the case in Java or C++ or many other languages.
- fweimer 3y agoI don't know. It seems fairly common to use std::panic::catch_unwind as a top-level error handler. compiler/rustc_driver_impl/src/lib.rs has this: /// The compiler currently unwinds with a special sentinel value to abort /// compilation on fatal errors. This function catches that sentinel and turns /// the panic into a `Result` instead. That's clearly using unwinding as a control flow primitive. There's another example in src/tools/rustfmt/src/lib.rs, in format_snippet, where panics apparently are just suppressed. I expect application servers for Rust to handle panics in a similar way: abort a specific request, but not terminate the whole process.
- skitter 3y agoIn JRE terms, Rust doesn't have Exceptions, but it has Errors.