3 ms·
The type system is yes, just not the borrow checker or the type checker. The type system is still relatively simple compared the type systems in Java/C#/C++/et
by Diggsey 7y ago
The type system is yes, just not the borrow checker or the type checker.
The type system is still relatively simple compared the type systems in Java/C#/C++/etc. Let's take Java's as an example because I think people regard it as being simple:
Building blocks of the type system:
Rust: Types, Traits
Java: Primitive types, classes, interfaces, (value types yet?)
Relationships between those building blocks:
Rust: Implements (Type <=> Trait)
Java: Extends (Class => Class | Interface => Interface), Implements (Class => Interface), Auto-boxes (Primitive/value type => Class)
Generics:
Works mostly the same in both languages. In Java you have to deal with the side-effects of type-erasure from time to time, and there's also the `? extends Y` syntax, for which Rust has no counterpart. In Rust you can have a generic parameter which is a lifetime, for which Java has no counterpart. Again though, these lifetimes are only used by the borrow checker, unlike normal type parameters, they do not affect the generated code.
Java appears simple because it is built on OOP concepts that are very familiar to most people. However, those OOP concepts contain a huge amount of complexity (inheritance trees, constructors, abstract classes, virtual/final methods, monitors, etc) and Rust simply gets rid of all of those concepts entirely. That's why I think it's simple.