Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Manual memory management is just one axis.

Some others are:

- `&mut T` which encodes that you have exclusive access to a value via a reference. I don't think there is any language with the same concept.

- `&T` which encodes the opposite of `&mut T` i.e. you know no one can change the value from underneath you.

- `self`/`value: T` for method receivers and argument which tells you ownership is relinquished (for non-Copy types). I think C++ can also model this with move semantics.

- `Send`/`Sync` bounds informing you how a value can and cannot be used across thread boundaries. I don't know of any language with an equivalent

- `Option<T>` and `Result<T, E>` encoding absence of values. Several other languages have equivalents, but, for example, Java's versions is less useful because they can still be `null`.

- Sum types in general. `Option<T>` and `Result<T, E>` are examples, but sum types are amazing for encoding 1-of-N possibilities. Not unique to Rust of course.

- Explicit integer promotion/demotion. Because Rust never does this implicitly you are forced to encode how it happens and think about how that can fail.

All of these are other ways Rust reduce cognitive load by encoding facts in the program text instead of relying on the programmer's working memory.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: