288 private links
Note: JS does not have the concept. If we wanted to mutate something, e’d need to put it in an object first, and then pass that object.
Yes, I missed that thought even if I am programming! We simply pass by value often and reassign the function output to a variable.
I’m still not entirely sure what object freezing is useful for — I feel like it’s rarely what you want.
Me too. I never found a good case for it.
I just want to be able to tell if a function is going to mess with its parameters.
It's a way to tell it. Does the parameters are mutated in-place?
To ensure the parameters
In JS, we can freeze an object. The object can be (deep) cloned in Go. ({...o}
as shallow clone in JS)
and I think I start to get it: Rust is awesome as interfaces because it can tell from the function signature if it mutates the parameters.
Indeed:
Similar ideas have been around for a while: In 1990, Philip Wadler wrote Linear types can change the world!
About safety in C or C++:
But those languages should be seen as asbestos.
It comes down to the multiple data structures in Rust.
But this complexity is simply a way to encode the reality of dealing with data in a multi-threaded environment, a way that can be checked at compile-time, before the program even gets a chance to run.
When you manage to make the type system work with you rather than against you, you can build things that would be wildly irresponsible to write in C and C++. And that’s the promise of Rust.