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

I'm curious what that assumption is based on. Rust and Nim are pretty different, and both of them have features that the other doesn't even try to have.


This is an interesting comparison of memory semantics I stumbled upon: https://paste.sr.ht/blob/731278535144f00fb0ecfc41d6ee4851323...

Nim's modern memory management (ARC/ORC) is fairly similar to Rust. ARC functions by reference-counting at compile time and automatically injecting destructors: which is broadly comparable to Rust's ownership + borrow checker.

(A big difference is that Nim's types are Copy by default: this leads to simpler code at the expense of performance. You have control over this, keeping memory safety, with `var`, `sink`, and others, as highlighted in the above link.)

https://nim-lang.org/blog/2020/10/15/introduction-to-arc-orc...

For reference cycles (the big limitation of reference counting), there's ORC: ARC + a lightweight tracing garbage collector.

As I understand it Rust also cannot handle reference cycles without manually implementing something similar.

https://nim-lang.org/blog/2020/12/08/introducing-orc.html

https://doc.rust-lang.org/book/ch15-06-reference-cycles.html


ARC is not "fairly similar" to idiomatic Rust. ARC is not idiomatic in Rust; it's a fallback for when you can't make do with lifetimes and borrowing.


Nim passes by value by default, which eliminates much of the complexity overhead of lifetimes and borrowing in most programs. (the compiler does optimize some of these into moves.)

But when you do want to pass by reference: that's where Nim's move semantics come in. These are what are fairly similar to Rust's lifetimes and borrowing, and what the paste.sr.ht link briefly goes over.

If you're interested, you can read more about Nim's move semantics here:

https://nim-lang.org/docs/destructors.html


Note that rust doesn’t have ARC; there is an atomic reference counted pointer, but it’s not automatic, which is what the a in ARC stands for.


Tongue in cheek: Then it's exactly like (modern) Nim, only that Nim does the fallbacking automatically as needed ;) There are lots of devils in the details, I assume.




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

Search: