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

> I'm coming to the view that Rust mostly requires less cognitive load than other languages.

This view is only remotely within the bounds of plausibility if you intended for "other languages" to refer exclusively to languages requiring manual memory management





Manual memory management is just on 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. 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.

- 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.


I don't think so?

In languages like Java their version of the Billion Dollar mistake doesn't have arbitrary Undefined Behaviour but it is going to blow up your program, so you're also going to need to track that or pay everywhere to keep checking your work - and since Rust doesn't have the mistake you don't need to do that.

Likewise C# apparently doesn't have arbitrary Undefined Behaviour for data races. But it does lose Sequential Consistency, so, humans can't successfully reason about non-trivial software when that happens, whereas safe Rust doesn't have data races so no problem.

Neither of these languages can model the no-defaults case, which is trivial in Rust and, ironically, plausible though not trivial in C++. So if you have no-defaults anywhere in your problem, Rust is fine with that, languages like Go and Java can't help you, "just imagine a default into existence and code around the problem" sounds like cognitive load to me.

Edited: Fix editorial mistake




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

Search: