Re:Zig; what I think after months of using it
by pkulak on Wednesday February 05, 2025 @01:34AM
(#42944703)
And on the whole, I prefer shadowing. I’ve never had a bug in either direction, but keeping everything immutable without shadowing means you spend all your brain power Naming Things.
[ Parent
| on HN ]
Re:Zig; what I think after months of using it
by lnenad on Wednesday February 05, 2025 @01:57AM
(#42944876)
I mean that's a really fake problem. How many times per line of code do you actually need to name variables and how many of those times you're shadowing a previously defined var. I'm guessing a very small amount.
Re:Zig; what I think after months of using it
by polanas on Wednesday February 05, 2025 @08:31AM
(#42948205)
In case of rust, it actually happens quite often. I find myself rarely needing to use mut, instead using functional approaches such as iterators and expressions. So a high percentage of the code is let statements
Re:Zig; what I think after months of using it
by lolinder on Wednesday February 05, 2025 @09:15AM
(#42948738)
Exactly. Shadowing is a super important complement to Rust's immutability. Without it immutability would be less useful and therefore less used.
Re:Zig; what I think after months of using it
by lolinder on Wednesday February 05, 2025 @09:14AM
(#42948722)
It's not just the naming things, it's also what you do after you've named them—if you can't shadow a name then you are stuck both coming up with new names and sifting through all the existing names in your autocomplete to try to remember which one is the real one at this point in the code. Get it wrong? There's a bug.
That's not a fake problem, it's a problem I've actually run into on a regular basis on languages that don't have shadowing.
Re:Zig; what I think after months of using it
by pkulak on Wednesday February 05, 2025 @12:17PM
(#42951812)
It absolutely depends on the language and how heavily it encourages immutability. For example, Rust and Elixor allow shadowing.
An awkward middle ground for me is Kotlin. It allows shadowing, but warns, so it might as well not be allowed. So you end up using lots of scoping tricks to avoid either making everything mutable, or having dozens of nearly-identical variables.