3 ms·
It is not useless though. There is a big difference between an unused variable and explicitly defining an unused variable. Kelly is designing Zig to do nothing
by flumpcakes 4y ago
It is not useless though. There is a big difference between an unused variable and explicitly defining an unused variable.
Kelly is designing Zig to do nothing surprising or change things underneath you. Even C does things that are surprising.
If you tell the compiler "Hey, I know this is unused but I am going to write it anyway" then the compiler _can_ make decisions such as eliding the variable.
I think we do all agree that it is sensible that a variable in code that is not used should be a compiler warning (if it is an error or not is clearly debatable).
- masklinn 4y ago> It is not useless though. True, it's actively harmful. > There is a big difference between an unused variable and explicitly defining an unused variable. Which is not helpful when you're only doing it to hide a compiler error foisted upon you. > Kelly is designing Zig to do nothing surprising or change things underneath you. Refusing to compile my code because I've an unused variable is certainly surprising. > If you tell the compiler "Hey, I know this is unused but I am going to write it anyway" then the compiler _can_ make decisions such as eliding the variable. That is the opposite of making sense. If you are actively forcing the use of a variable then the compiler removing it anyway is exactly surprising. > I think we do all agree that it is sensible that a variable in code that is not used should be a compiler warning (if it is an error or not is clearly debatable). 1. that it's an error is the entire problem here 2. and as far as I'm concerned it's a ridiculously weak warning, if your standard is that no action should be useless you need an unused store error, which subsume unused variables
- flumpcakes 4y ago> That is the opposite of making sense. If you are actively forcing the use of a variable then the compiler removing it anyway is exactly surprising. I disagree, you are actively telling the compiler that this is dead code.
- masklinn 4y ago> I disagree, you are actively telling the compiler that this is dead code. No, you would be doing that by removing the code. You are telling the compiler that this is code you want and to shut the fuck up.
- alpaca128 4y agoThis method is more a hack to confuse the compiler than a clean solution, and now this unused variable could stay in the code forever because the compiler won't ever mention it again. Using `_ = var` to prevent the error is just as bad as handling Java exceptions with empty catch blocks.