News for hackers. Stuff that matters.
Re:Zig, the Small Language by avgcorrection on Wednesday September 07, 2022 @12:47PM (#32753010)
That was the first suggestion that Kelley posted on the issue and judging by the reactions people weren’t happy with it.
Re:Zig, the Small Language by TakeBlaster16 on Wednesday September 07, 2022 @12:52PM (#32753079)
His suggestion is even counterproductive in a way, because it makes it more likely people will accidentally commit unused vars they have silenced. I _want_ the compiler to help me find unused things... just not yet. Wait until my pre-commit hook to yell at me please!
Re:Zig, the Small Language by anonymoushn on Wednesday September 07, 2022 @12:54PM (#32753104)
I've definitely done this, and this is a good argument for changing the behavior.
Re:Zig, the Small Language by masklinn on Wednesday September 07, 2022 @12:49PM (#32753035)
Completely unsurprisingly. "Add useless garbage to work around the stupid decisions we impose on you" is not very appreciated.
Re:Zig, the Small Language by flumpcakes on Wednesday September 07, 2022 @02:59PM (#32754873)
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).

Re:Zig, the Small Language by masklinn on Wednesday September 07, 2022 @03:22PM (#32755329)
> 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

Re:Zig, the Small Language by flumpcakes on Wednesday September 07, 2022 @03:26PM (#32755404)
> 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.

Re:Zig, the Small Language by masklinn on Wednesday September 07, 2022 @03:45PM (#32755692)
> 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.

Re:Zig, the Small Language by alpaca128 on Thursday September 08, 2022 @04:53AM (#32763039)
This 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.