Hacker News new | ask | show | jobs
by masklinn 1221 days ago
> Can someone explain why Rust has mutability?

Because it’s target domain requires reliable efficiency.

> Wouldn't it be better if we could just have the compiler guarantee that functions marked as such

As such what?

> are doing TCO

TCO is worthless, and Rust does not have TCE, nor does it care about TCE.

> so algorithms would look better and had the full benefit of persistent data structures?

Rust does not significantly care for persistent data structures, there are crates which provide them, but not the standard library.

Rust is not a functional language.

1 comments

"Worthless" is a bit strong. The Rust devs want to add TCO/TCE, but there are still problems left to solve. The "become" keyword is already reserved in anticipation of guaranteed tail calls being added.

https://github.com/rust-lang/rfcs/issues/2691

> "Worthless" is a bit strong.

No, TCO is worthless, it’s an unreliable optimisation.

Compiler optimizations are best-effort. -O3 gets you 90% of the optimization for 10% of the work of writing hand-rolled assembly. Individual optimizations are not guaranteed, and sometimes even regress in newer compiler versions, but everyone uses them because overall programs run much faster with optimizations than without. I don't see how TCO is any different. Would you say all optimizations are worthless because they're not guaranteed?
> Would you say all optimizations are worthless because they're not guaranteed?

Context is relevant, the context here is language semantics, not things going faster.

TCO is fine to make things go faster, like inlining, unrolling, LICM, ....

TCO is hot garbage when you rely on it for program correctness.

Weird how none of that context was present in your first two iterations of the claim.
If given explicit support in a language then no it's not. Especially with the keyword approach rust is taking, the compiler will guarantee the semantics.

Do you believe the exec system call is similarly unreliable at replacing your process image? Amazing that unix systems work at all

> If given explicit support in a language then no it's not. Especially with the keyword approach rust is taking, the compiler will guarantee the semantics.

Then it's TCE not TCO.

> Do you believe the exec system call is similarly unreliable at replacing your process image?

Exec is entirely unlike TCO. If exec was a syscall which sometimes did and sometimes did not replace your process image, then it'd be like TCO, and it'd be similarly unreliable.

I think it would have helped if you'd defined your terms earlier. Wikipedia, for example, doesn't distinguish between the terminology TCO and TCE: https://en.wikipedia.org/wiki/Tail_call