3 ms·
One problem I see with this decision is that code will now be littered with: _ = bla; _ = blub; ...which have been forgotten during development. So t
by flohofwoe 5y ago
One problem I see with this decision is that code will now be littered with:
_ = bla;
_ = blub;
...which have been forgotten during development.
So the next thing that's needed is an error if 'bla' or 'blub' are actually used elsewhere ;)
- mediocregopher 5y agoI've been 99% a Go developer since 2015-ish, and this is not something I've ever encountered, in general people just don't leave unused variables lying around. The compile time check does highlight logic errors frequently enough though, so I'm very glad it's there.
- lillecarl 5y agoMore often than not I end up creating variables for a bunch of chained function calls just to get the debugger output right, I might be holding it wrong though.
- DangitBobby 5y agoIt's mostly a problem when you're in the middle of writing something and you're trying to figure out what's going wrong, so you start commenting stuff out... And now you have un-used variables that you have to rename to _ for no good reason. It just adds busywork.
- int_19h 5y agoIt would be nice if Zig had statement- and expression-level comments, similar to how most Lisps let you comment out whole S-exprs (which still have to be valid). Then it could allow variables that are referenced only from such comments.
- dilap 5y agoSure, but this is an easy thing to audit for (could even be automated as part of some CI system, if you wanted).
- AndyKelley 5y agoPlease note there is an accepted proposal[1] to add an unused keyword, making it possible to detect conflicts between things being marked unused and actually being used, and improving tooling integration. [1]: https://github.com/ziglang/zig/issues/10245 https://github.com/ziglang/zig/issues/10245
- nicoburns 5y agoI think there should definitely be a global option to disable this during development. This makes temporarily trying something out (e.g commenting out some code to run only part of it) a massive pain, as you have to go up and edit the variable definition as well as the code using it).
- dureuill 5y agoagreed. Rust has a warning for unused items, which is indeed interesting to catch logic errors (variables that should be used, but aren't). No need to fail compilation for this. It is then on you to deny warnings in CI to ensure that they are all handled before the code actually lands
- kaba0 5y agoFully agree. I meet with it mostly in typescript’s linter, but recursively having to comment out things is just simply terrible. Of course it is great for prod, but for debug it is very questionable.
- dnautics 5y agoI like this a lot. Though, many pls offer making the identifier start with _ to make it unused well.