@cheng@cornerof.world: > I've just come to realize that (latest vision of) Nim and Rust's memory management share a lot in > common, and it's just the preferences of how to do things, which are imposed by the language design, > making Rust apparently more difficult to use than Nim > > Some correspondences: > > 1. Rust's `&T` is Nim's `lent T` > 2. Rust's `&mut T` is Nim's `var T` > 3. Nim's `sink T` is Rust's `T` without `Copy` trait > 4. Nim's `T` is Rust's `T` with `Copy` trait > 5. Nim's `ref T` is Rust's `Rc` > 6. Nim's `ptr T` is Rust's `*T` > > And then the differences, contributing to the very different overall feelings when programming in: > > 1. Rust prefers to use `&T` and `&mut T` to stay performant as much as possible; while Nim uses > `Rc` for all its managed/safe references, and `lent T` `var T` are only used for function > parameters/returns. Trying to use `&T` and `&mut T` everywhere causes a lot of complexity and > restriction of how to do things, while Nim's approach `Rc` is much easier to use, but is more > opinionate and relaxed on performance > > 2. Rust uses move semantics by default, an assignment on a type without `Copy` trait is seen as a > move. Nim uses copy semantics by default, but has `sink T` to annoate a function parameter to > have move semantics, and the compiler tries to optimize copies into moves > > 3. Rust handles immutability with two kinds of references `&T` and `&mut T`, which additionally have > an exclusive access semantics. This design coupled with interior mutability can be very > confusing, but it is designed so to help with efficient multi-threading, which is a primary goal > movitated Rust in the first place. Nim on the other hand handles immutability by tracking write > side-effects of programs which operate on the types > > 4. For safe multi-threading, Rust checks whether a type can be sent or shared among threads in > compile-time; some types like `Rc` can't be sent or shared. Nim does not allow sharing data > among threads at all, but allows all types to be sent between threads, although the data has to > be checked for isolation in runtime for the general case