←back to thread

452 points birdculture | 1 comments | | HN request time: 0.206s | source
Show context
mdwhatcott ◴[] No.43979711[source]
[flagged]
replies(13): >>43979747 #>>43980029 #>>43980452 #>>43980582 #>>43980897 #>>43981065 #>>43981118 #>>43981329 #>>43981636 #>>43981787 #>>43981862 #>>43982909 #>>43992716 #
melodyogonna ◴[] No.43981636[source]
Rust design decisions are pretty hard to understand sometimes, Mojo is another language with a borrow-checker but it is not nearly as hard to learn as Rust due to making a few decisions. First is value semantics, in Rust people are told to always clone when learning, why isn't this semantics built into the language? It is what you have in most static languages - C, C++, Go, etc. This is the mental model many people come to Rust with.

Secondary, Mojo's lifetime does not tell the compiler when a value is safe to use but when it is safe to delete, in this way the lifetime is not scope based, references will extend the lifetime of the value they reference, but values will be destroyed immediately after their last use. In Mojo you'll never see "value does not live long enough".

Just these two design decisions defines away so many ergonomic issues.

replies(3): >>43982040 #>>43983851 #>>43991263 #
1. aw1621107 ◴[] No.43991263[source]
> but values will be destroyed immediately after their last use

For what it's worth, it appears this was considered for Rust at some point but the devs decided against it. As described by Steve Klabnik in 2018 [0]:

> This was called “early drop”, and we didn’t implement it because of worries about unsafe code. Yes, the compiler could tell for safe code, and it would be fine, but unsafe code cannot, by definition, be checked.

[0]: https://users.rust-lang.org/t/drop-values-as-soon-as-possibl...