5 ms·
I like that in rust one can reuse variable names, since they are dead anyway. Makes sense to ‘update’ the old name with the new value, sort of like a swap-and-k
by clord 4y ago
I like that in rust one can reuse variable names, since they are dead anyway. Makes sense to ‘update’ the old name with the new value, sort of like a swap-and-kill. Does austral have this? Seems like no reason not to.
- zetalyrae 4y agoNo, in fact variable shadowing is not allowed.
- clord 4y agoAny other mechanism for fixing the ephemeral name problem? I don’t like having to invent meaningless names.
- tinyspacewizard 4y agoNo names, just function piping.
- jiggawatts 4y agoThis is the safe approach. Rust’s name shadowing is technically safe, but a massive footgun because humans are human and assume that in the same scope the same name refers to the same thing. With name shadowing, you have to read through every line to make sure that the otherwise immutable value hasn’t been replaced with an impostor. IMHO, it’s one of the worst Rust design decisions and shouldn’t be copied. People will say they’re too lazy to come up with temporary variable names, meanwhile Rust doesn’t have multiple dispatch so every fn name has to be unique, which I personally find more irritating…
- masklinn 4y ago> This is the safe approach. This is the painful approach, which is demonstrated in this very introductory document: let f: File := openFile("test.txt"); let f1: File := writeString(f, "First line"); let f2: File := writeString(f1, "Another line"); ... Foo63 is one of those things I do not miss from Erlang. > IMHO, it’s one of the worst Rust design decisions and shouldn’t be copied. 100% disagree. It's even more valuable to rust because of things like capture clause patterns. > People will say they’re too lazy to come up with temporary variable names No, people will say that most of the time temporary variable names make no sense and add no information. When you have an input of `T: AsRef<U>` and literally the first thing you do is ref' it, there's no value whatsoever to having two different names.
- _dain_ 4y agoBorrowing exists to fix this problem, I believe you can do something like this? let f: File := openFile("filename.txt"); writeString(&!f, "first line"); writeString(&!f, "second line"); writeString(&!f, "third line"); closeFile(f);