News for hackers. Stuff that matters.
Re:Zig, the Small Language by j16sdiz on Wednesday September 07, 2022 @12:44PM (#32752969)
You can always do ' _ = your_varible', don't have to comment individuals
Re:Zig, the Small Language by dmytrish on Wednesday September 07, 2022 @12:48PM (#32753023)
That makes unused variables "used", which defeats the point of the check.
Re:Zig, the Small Language by vinay_ys on Wednesday September 07, 2022 @12:51PM (#32753069)
Yep. Exactly. We want to be able to silence the compiler for a few iterations while the code is taking shape and then cleanup all the compiler lints in later iteration. In production CI pipeline, we can have all compiler lints on. This capability is very much needed to have a fast local dev iteration where compiler can assist but not impede.
Re:Zig, the Small Language by simlevesque on Wednesday September 07, 2022 @01:27PM (#32753500)
Eslint has `// eslint-disable-next-line no-unused-variables`, it is very useful.

I'd prefer `eslint-expect-error-next-line` instead to warm me when the comment is actually useless but it's better than what Zig seem to do.

Re:Zig, the Small Language by TakeBlaster16 on Wednesday September 07, 2022 @01:41PM (#32753663)
There's a nice eslint plugin for disable-line hygiene: https://www.npmjs.com/package/eslint-plugin-eslint-comments

I do wish Rust had something like this too

Re:Zig, the Small Language by steveklabnik on Wednesday September 07, 2022 @02:06PM (#32754002)
https://play.rust-lang.org/?version=stable&mode=debug&editio...

You can put it at the top of your file with a #! too, if you want it to apply to the whole file.

Re:Zig, the Small Language by TakeBlaster16 on Wednesday September 07, 2022 @02:17PM (#32754139)
Oops I didn't explain clearly. Take this code:

  pub fn abc() -> usize {
      #[allow(deprecated)]
      "abc".len()
  }
I want it to complain about the "allow", because there was never any deprecated warning emitted in the first place. Maybe it would be called #[expect(deprecated)]

I refactor code all the time and find these stray "allow"s that aren't doing anything anymore

Re:Zig, the Small Language by eddyb on Wednesday September 07, 2022 @03:11PM (#32755104)
> Maybe it would be called #[expect(deprecated)]

Both this and the reply saying you should open an RFC worry me that it was tongue-in-cheek.

Or maybe it's the obvious name choice, heh, because it literally exists with that very syntax: https://play.rust-lang.org/?version=nightly&mode=debug&editi...

Not stable yet, as you can see, but all the RFC and implementation work has been done, and a stabilization report was even put forward back in July: https://github.com/rust-lang/rust/issues/54503#issuecomment-...

Re:Zig, the Small Language by TakeBlaster16 on Wednesday September 07, 2022 @03:52PM (#32755802)
That's hilarious, I had no idea! I'm glad I didn't embarrass myself by proposing an RFC. Thanks for the links!
Re:Zig, the Small Language by voorwerpjes on Wednesday September 07, 2022 @02:55PM (#32754811)
This would be really cool! you should open up a RFC for it.
Re:Zig, the Small Language by steveklabnik on Wednesday September 07, 2022 @02:20PM (#32754178)
Ah, yeah that would be cool. Sorry for misunderstanding!
Re:Zig, the Small Language by simlevesque on Wednesday September 07, 2022 @02:09PM (#32754035)
Thank you !
Re:Zig, the Small Language by iainmerrick on Wednesday September 07, 2022 @03:07PM (#32755026)
But then what if you accidentally check in that workaround?

The strict compiler check would have had exactly the opposite effect from the intended one.

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.