News for hackers. Stuff that matters.
Re:Zig, the Small Language by TakeBlaster16 on Wednesday September 07, 2022 @12:37PM (#32752885)
I tried Zig recently but I found the unsilenceable lints to be a huge productivity killer. I actually posted a link to the GitHub issue this morning. https://news.ycombinator.com/item?id=32751317

This makes a normal workflow with `watchexec zig test` basically impossible, since before I can even run the tests I have to spend time hunting down which variables are used/unused at the moment and (un)commenting them. And it seems like they're planning to double down on this by making you adjust even more trivial things like public/private and var/const before it will even compile your code. https://github.com/ziglang/zig/issues/335 https://github.com/ziglang/zig/issues/224

Maybe I'm a bad developer, but my code is never perfect the first time around. I always spend time experimenting and refining my designs. I want to find a design that works, and only then spend time polishing and prettifying before I git push.

I do understand the reasoning (they don't want people committing poor quality code), but this implementation just seems completely backwards to me. It breaks the natural order. It's like saying we won't let you ctrl+s until your tests pass to make sure you don't commit broken code. Stop nannying me and let me get my work done!

Re:Zig, the Small Language by masklinn on Wednesday September 07, 2022 @12:57PM (#32753152)
> I do understand the reasoning (they don't want people committing poor quality code)

Not that this lint actually achieves that, or even prevents real errors. Go has the same, and it's so simplistic as to only be annoying. For instance not sure whether this fails in Zig but Go will allow this:

    v1, err := Foo()
    if err != nil {
        return nil, err
    }
    v2, err := Bar(v1)
    return v2, nil
Error of second call is never checked, but go has no issue with that, because it only tracks definitions per use.

    v1, err := Foo()
    v2, err := Bar(v1)
    if err != nil {
        return nil, err
    }
    return v2, nil
also works fine, despite probably sending complete nonsense to Bar, for the same reason.

But then it's an absolute pain in the ass every time you're fucking around and stop using a debug import or whatever.

Re:Zig, the Small Language by TakeBlaster16 on Wednesday September 07, 2022 @01:29PM (#32753519)
Zig seems to behave similarly. This compiles:

  export fn x() i32 {
      var a: i32 = 1; // okay
      a = 2;
      return a;
  }
This does not:

  export fn x() i32 {
      var a: i32 = 1; // unused variable
      var a2: i32 = 2;
      return a2;
  }
> Not that this lint actually achieves that, or even prevents real errors.

I have to agree. If there's one thing I've learned over the years, it's that you can't prevent bad code by enforcing lint errors.

Re:Zig, the Small Language by cle on Wednesday September 07, 2022 @02:20PM (#32754185)
> If there's one thing I've learned over the years, it's that you can't prevent bad code by enforcing lint errors.

I completely disagree, I regularly catch mistakes/bugs in my own code due to enforced linting errors (both locally and in CI), and just in the past few months I can recall numerous instances where CI linting caught bugs in teammates' code too.

There are both false positives and false negatives with linting, but that doesn't make it useless at all.

Re:Zig, the Small Language by swsieber on Wednesday September 07, 2022 @02:26PM (#32754300)
And there are good and bad lints. If you want a somewhat view on what lints are good and bad go find some issues for Rust that discuss how to categorize a particular lint.
Re:Zig, the Small Language by nkozyra on Wednesday September 07, 2022 @02:28PM (#32754332)
I don't think that's quite the same issue. That `a` is reassigned doesn't make it unused. It is, after all, a variable.

And that's why this issue is kind of hard. It's why I end up block scoping a lot of error code in Go, which is ugly but generally safer.

Re:Zig, the Small Language by masklinn on Wednesday September 07, 2022 @03:17PM (#32755232)
> I don't think that's quite the same issue.

It is.

> That `a` is reassigned doesn't make it unused. It is, after all, a variable.

But that's exactly why it's bad, "unused variable" is not a super useful signal in the first place, and if you assert that everything must be used then you need to protect against "unused stores" instead.

SSA tells us there is essentially no difference between assigning and reassigning.

Re:Zig, the Small Language by Akronymus on Wednesday September 07, 2022 @06:57PM (#32758278)
> I have to agree. If there's one thing I've learned over the years, it's that you can't prevent bad code by enforcing lint errors.

A lot of simple cases can be handled with linting rules, BUT that, IMO requires a few additional things. Namely, being expression based, rather than statement based, and enforcing something like a hindley milner type system.

Re:Zig, the Small Language by Gibbon1 on Thursday September 08, 2022 @01:53AM (#32761695)
Zig will also let you return references to stack allocated objects.
Re:Zig, the Small Language by llimllib on Wednesday September 07, 2022 @01:09PM (#32753304)
This really irritated me when I started working with go, but it stopped bothering me and now I even mostly like it.

The missing error checks are annoying, but if you have appropriate editor config it is hard to miss them: https://cdn.billmill.org/static/newsyctmp/warning.png

Basically writing go without `staticcheck`[1] is not recommended. If you do have it set up, it's pretty easy to avoid simple errors like that. I do wish the compiler checked it for you.

[1]: https://staticcheck.io/

Re:Zig, the Small Language by masklinn on Wednesday September 07, 2022 @01:42PM (#32753685)
> This really irritated me when I started working with go, but it stopped bothering me and now I even mostly like it.

Don’t get me wrong I like a good unused code warning.

What frustrates me is that Go’s is dumb / unreliable, and it will stop you from working entirely until you’ve complied with this whim, which has a fraction of a percent chance of identifying a real bug.

> Basically writing go without `staticcheck`[1] is not recommended.

So why have these things as mandatory compiler errors?

Re:Zig, the Small Language by mirekrusin on Wednesday September 07, 2022 @02:21PM (#32754208)
So you don't publish it.

I guess they could have levels and allow them in debug mode or with special flag or something?

Re:Zig, the Small Language by pcwalton on Wednesday September 07, 2022 @02:35PM (#32754453)
-Werror by default would still be mildly annoying, but I'd like it a lot better than what Go and Zig do. At least then I could shell alias "go" to "go -Wno-error".
Re:Zig, the Small Language by masklinn on Wednesday September 07, 2022 @03:19PM (#32755265)
> So you don't publish it.

Why do they care?

> I guess they could have levels and allow them in debug mode or with special flag or something?

Well yes, that's how normal compilers do things.

Re:Zig, the Small Language by mayormcheeseman on Thursday September 08, 2022 @12:21AM (#32761148)
I’d assume they care because Go was designed to keep the codebase as “neat” and clean as possible when being worked on by many developers. Given enough time and developers, things like unused variables will start to seep in and make the codebase dirtier.

Of course if you’re the only developer working on your own codebase, you’d wonder why they care but you’re also not the main group they were targeting.

Re:Zig, the Small Language by masklinn on Thursday September 08, 2022 @12:46AM (#32761286)
> I’d assume they care because Go was designed to keep the codebase as “neat” and clean as possible when being worked on by many developers

So someone’s anal retentive was made into a langage mandate rather than anything actually useful?

> Given enough time and developers, things like unused variables will start to seep in and make the codebase dirtier.

Why are dead variables any dirtier than dead stores? Or unchecked errors?

Re:Zig, the Small Language by naasking on Friday September 09, 2022 @07:58AM (#32778060)
> Why are dead variables any dirtier than dead stores?

If you mean stores to fresh local variables, I assume that should also count in a proper/ideal implementation of this.

If the idea is for code to be literally WYSISWYG, then your compiler will no longer eliminate variables or code for you, so you have to do it.

In principle, a dead variable in final code is also almost certainly a mistake: either by not including the variable in the computation or for declaring the variable at all. Maybe a little annoying while you're figuring something out, but makes sense in the context of polished code.

Re:Zig, the Small Language by masklinn on Sunday September 11, 2022 @10:27AM (#32799886)
> If you mean stores to fresh local variables

I mean stores for which there is no load.

> I assume that should also count in a proper/ideal implementation of this.

It certainly does in a proper implementation, but not in zig. Or go.

> If the idea is for code to be literally WYSISWYG, then your compiler will no longer eliminate variables or code for you, so you have to do it.

That sounds stupid.

> a dead variable in final code is also almost certainly a mistake

See “final code” is the issue at hand. The problem with go is that it specifically does not do that. It has a half-assed implementation which it forces upon you all the time.

> Maybe a little annoying while you're figuring something out

It’s a bloody nuisance when you new figuring things out or in the middle or refactoring something.

> but makes sense in the context of polished code.

There’s a ton more which makes sense “in the context of polished code” which go can’t be arsed to do.

Checking that errors are not implicitly ignored for starters.

Re:Zig, the Small Language by naasking on Monday September 12, 2022 @08:58AM (#32809467)
> I mean stores for which there is no load.

Stores for which there are no load can still be observable in concurrent scenarios. That's why I specified stores to locals with no load because those are not observable.

> That sounds stupid.

Sounds totally reasonable to me in scenarios where you need the output of the compiler to be very predictable.

Re:Zig, the Small Language by dureuill on Saturday September 10, 2022 @04:19PM (#32794279)
i could understand this in 1995, but in 2015? We have peer reviews, and CI. Let's deny warnings there, and allow them during development.
Re:Zig, the Small Language by thegeekpirate on Wednesday September 07, 2022 @06:34PM (#32758029)
Use golangci-lint (https://golangci-lint.run, https://github.com/golangci/golangci-lint) which combines all of the best lints (including staticcheck).
Re:Zig, the Small Language by anonymoushn on Wednesday September 07, 2022 @01:28PM (#32753510)
This lint doesn't help with these situations, but other rules around values belonging to error unions would prevent you from porting this golang code to Zig.
Re:Zig, the Small Language by stjohnswarts on Wednesday September 07, 2022 @10:46PM (#32760488)
is there no way to swap out lint "ignore" files for fucking around vs "I'm getting ready to test/release" rules ? That's what I do with c++ and python. I haven't only mucked around a bit with zig on godbolt though.
Re:Zig, the Small Language by WalterBright on Wednesday September 07, 2022 @01:09PM (#32753308)
There's a push-and-pull on this in D, too. For example, sometimes I want a backtrace at a certain point, so I'll add an `assert(0);` there. The compiler complains that the rest of the code is unreachable. I then have to block out the code with a `static if (0) { ... }`, or comment it out, which is annoying.

But most everyone else likes this, so it stays in.

There are no real right answers here. Adding a switch for it just brings its own annoyance (every compiler switch is a bug). You just wind up settling for a local optimum.

Re:Zig, the Small Language by oconnor663 on Wednesday September 07, 2022 @02:24PM (#32754260)
> every compiler switch is a bug

I totally get where this is coming from, but on the other hand it seems like Rust and Zig both get a lot of value from having the compiler understand the difference between debug and release modes, and it seems like modern C++ suffers somewhat from not having any built-in way to do something similar. The optimal number of compiler switches might not be zero.

Re:Zig, the Small Language by WalterBright on Wednesday September 07, 2022 @02:32PM (#32754397)
D literally has the switches `-release` and `-debug`.
Re:Zig, the Small Language by Yahivin on Wednesday September 07, 2022 @05:39PM (#32757322)
It seems to me that a possible improvement would be for the compiler to error on unreachable code in `-release` and to warn in `-debug`.
Re:Zig, the Small Language by pwdisswordfish9 on Thursday September 08, 2022 @03:55AM (#32762620)
Why don’t you fix those bugs?
Re:Zig, the Small Language by WalterBright on Thursday September 08, 2022 @04:06AM (#32762706)
-release is in there for magazine journalists who run benchmarks. -debug is for project managers to bring order to special debug code.
Re:Zig, the Small Language by mhh__ on Thursday September 08, 2022 @12:08AM (#32761078)
Nearly everyone I speak to hates the unreachable error messages, by the way.

It's not useless to have them but they can be utterly infuriating for exactly the reason you mention since most projects have warnings-are-errors turned on.

The way I shut it up in a class is usually by branching on the this pointer. Sneaky.

Re:Zig, the Small Language by politician on Wednesday September 07, 2022 @01:25PM (#32753468)
Have you considered adding a dedicated `breakpoint` keyword for this use case? Linters could ignore it, but the compiler could warn or error. The problem with workarounds like `assert(0)` is that the linter lacks context to do the right thing.
Re:Zig, the Small Language by WalterBright on Wednesday September 07, 2022 @01:50PM (#32753781)
Adding another feature is always tempting, and there are daily new feature requests for D.

We simply have to have a very high bar for new features.

Re:Zig, the Small Language by cxr on Thursday September 08, 2022 @07:29AM (#32764041)
It's a good principle to pursue. But additional language features for production codebases vs toolchain features that happen to lean on changes to the language as a matter of UI are worth considering separately.
Re:Zig, the Small Language by bzxcvbn on Wednesday September 07, 2022 @03:08PM (#32755037)
Doesn't D have a debugger? Hitting F9 then F5 sounds a lot faster than fiddling around with the code, hoping that you forget to remove the assert before you go home and that you won't spend time pleasing the compiler.
Re:Zig, the Small Language by WalterBright on Wednesday September 07, 2022 @05:18PM (#32757047)
Yes, gdb. I don't particularly like gdb, though.

> hoping that you forget to remove the assert

I routinely add a lot of instrumentation when developing code. I use `git diff` to remove it before committing.

The compiler builds itself fast enough that this is not a problem. I have one window on the source, the other on the build.

Re:Zig, the Small Language by titzer on Wednesday September 07, 2022 @05:00PM (#32756796)
In Virgil I usually do "var x = 1/0;", but there's a command-line option "-fatal-calls=<method glob>", so you can crash on a call to a specific set of methods and get a stacktrace.
Re:Zig, the Small Language by sph on Wednesday September 07, 2022 @02:20PM (#32754199)
You and me both, in fact I made my voice heard in the Github issue.

What's damning is how much Stockholm Syndrome there is around this feature, with people saying it's no big deal and it helps catch bugs. It's more annoying than helpful, and it catches a very small amount of corner cases, while completely killing productivity.

And you know what's the reasoning behind this? "Zig doesn't have warnings." As if it's a massive undertaking to add warnings to a compiler. What a sorry excuse.

I have ranted about this before, so I already feel my blood pressure going up.

Re:Zig, the Small Language by kristoff_it on Wednesday September 07, 2022 @02:39PM (#32754530)
> And you know what's the reasoning behind this? "Zig doesn't have warnings." As if it's a massive undertaking to add warnings to a compiler. What a sorry excuse.

Setting aside the unused variables issue for a moment, you might want to take a moment to ponder the fact that not having warning messages is an explicit design choice, not a missing feature.

Re:Zig, the Small Language by lopatin on Wednesday September 07, 2022 @03:05PM (#32754986)
A dogmatic one, by the sounds of it.
Re:Zig, the Small Language by kristoff_it on Wednesday September 07, 2022 @03:26PM (#32755399)
Well if one never stops to think about its potential merits, it can surely only be perceived as dogmatic. One thing is evaluating a choice in its full context and not liking it, another is demanding to have your vision be understood and accepted without being willing to grant the same courtesy first.
Re:Zig, the Small Language by lopatin on Wednesday September 07, 2022 @07:01PM (#32758341)
> you might want to take a moment to ponder the fact

> Well if one never stops to think about its potential merits

Listing some of those merits may be more productive than insisting people aren't thinking about it hard enough

Re:Zig, the Small Language by naasking on Friday September 09, 2022 @08:07AM (#32778130)
I don't program in Zig, but I can think of a few reasons in principle:

1. WYSIWIG compiler: how many people have been complaining lately about C compilers eliminating code on them due to undefined behaviour? If you eliminate certain optimizations so your complier doesn't do this, like dead code/variable elimination, then what the code looks like is exactly what executes. This means some important optimizations may have to be done by hand. Eliminating dead variables could be one of them.

2. Arguably dead variables are a mistake. Either they're a (major) mistake because you neglected to include a value in your computation, or a (minor) mistake because you declared a superfluous variable that's never used.

3. If you want your code to be clear and as self-documenting as possible, unused variables are an impediment. I can't speak to the accuracy of Zig's analysis, but I can see how it would be annoying while working out an algorithm.

Re:Zig, the Small Language by bmacho on Thursday September 08, 2022 @03:14PM (#32770579)
> another is demanding to have your vision be understood and accepted without being willing to grant the same courtesy first.

Is it available somewhere? I can't think anything why that compiler patch[0] can't be upstream (of course not default, but under a flag/different build mode/config option).

[0]: https://github.com/ziglang/zig/issues/335#issuecomment-10138...

Re:Zig, the Small Language by avgcorrection on Wednesday September 07, 2022 @03:10PM (#32755083)
Maybe this becomes the equivalent of `go fmt` in 10 years. “How I learned to stop worrying and love errors-only”
Re:Zig, the Small Language by edflsafoiewq on Wednesday September 07, 2022 @03:17PM (#32755237)
We've had -Werror forever, the consensus is it's a bad idea. In addition to everything else, you can't ever change the warnings, including fixing bugs in them, without potentially breaking code.
Re:Zig, the Small Language by von_lohengramm on Wednesday September 07, 2022 @04:51PM (#32756656)
> We've had -Werror forever, the consensus is it's a bad idea.

Says who? Package repo maintainers? -Werror is actually quite divisive.

Re:Zig, the Small Language by plorkyeran on Wednesday September 07, 2022 @11:17PM (#32760751)
Anyone who wants to be able to compile a program with a different or newer compiler than the author last tested it on.
Re:Zig, the Small Language by ok_dad on Wednesday September 07, 2022 @02:35PM (#32754455)
So don't use Zig? I don't get why you're so angry about something someone else likes. Just don't use it or look at it! So easy...
Re:Zig, the Small Language by chongli on Wednesday September 07, 2022 @03:38PM (#32755615)
So don't use Zig?

I see this comment a lot in response to feedback: "Don't like it? Don't use it!" Every single time, it reads to me as "stop complaining!" For as many times as I've seen the comment, I haven't been able to read it any other way.

Am I being uncharitable or is it really just a clear-cut attempt to silence debate?

Re:Zig, the Small Language by geodel on Wednesday September 07, 2022 @03:52PM (#32755806)
Well it would depend on context. For a FOSS software in domain where there are tons of other options, it is much easier to use what one likes and ignore what one doesn't. So calling it silencing the debate sounds too strong when software in question is not some controlling the world type.

On the other hand in case cloud services like those provided Google/FB/Twitter/Cloudflare etc it is much more difficult to just go with "Don't use if you don't like" because not only there are not much alternative but also because sometimes Cloud service providers act in unison. So if one is pushed out from a service they are likely to be pushed from all other services too.

Re:Zig, the Small Language by chongli on Wednesday September 07, 2022 @04:15PM (#32756144)
"Don't like it? Just fork it!" is a variant I see a lot in the FOSS world. It's equally pernicious in my view. Either you end up maintaining your own fork that nobody uses (and who wants to do that) or the fork is successful and half the community starts hating you for causing more fragmentation. Perhaps the most recent example of this I can think of is neovim, though in the language world python 2 vs 3 is so infamous that people have started hating the entire community from the outside.

All of this says to me that Zig is taking the wrong approach. Making highly controversial, opinionated features the standard with no way to opt out just leads to these endless debates. Languages (or any tools, for that matter) that stay out of the debate and just give everyone a flag tend to have much more welcoming communities.

Re:Zig, the Small Language by Tozen on Thursday September 08, 2022 @10:29AM (#32766082)
I agree with a lot of this, in terms of the polarization and tribalism, which is often the result. Unfortunately, there is little that can be usually done, except use other programming languages (which are more agreeable) or fork/make your own.
Re:Zig, the Small Language by chongli on Thursday September 08, 2022 @12:01PM (#32767518)
Yeah, it's just really frustrating when a language like Zig comes along. It does so many things right and seems to have a really good philosophy. But then it includes some highly opinionated "features" that make it a non-starter for so many people who could otherwise benefit from it.
Re:Zig, the Small Language by ok_dad on Wednesday September 07, 2022 @03:56PM (#32755855)
Yea, I was under the assumption there are literally thousands of programming languages and you can fork most of them when I replied.

I’m not usually a “just don’t use it” kind of guy, but in this case it’s valid, imo.

Re:Zig, the Small Language by RussianCow on Wednesday September 07, 2022 @02:40PM (#32754544)
If I didn't use any programming language that I hated any part of, I wouldn't be able to write code.
Re:Zig, the Small Language by md224 on Wednesday September 07, 2022 @03:05PM (#32754976)
What if the person you're replying to really, really likes Zig except for this one aspect of it?
Re:Zig, the Small Language by ok_dad on Wednesday September 07, 2022 @03:37PM (#32755596)
Then they shouldn't get so mad at something that's merely annoying; it's bad for the heart and circulatory system.
Re:Zig, the Small Language by geodel on Wednesday September 07, 2022 @10:32PM (#32760387)
Yeah, exactly right! I mean we all adjust people, places, things all the time. There is nothing special about programing languages that it has to be perfect fit for each feature one desires.
Re:Zig, the Small Language by runald on Wednesday September 07, 2022 @10:42PM (#32760460)
Is that why you ignored all the other responses to your comment?
Re:Zig, the Small Language by LAC-Tech on Wednesday September 07, 2022 @11:29PM (#32760824)
Because only get upset about this because they love zig
Re:Zig, the Small Language by ptato on Wednesday September 07, 2022 @01:22PM (#32753447)
There's a lot of people in the community that feel this way as well but tolerate it. I think it's a certainty that whenever zig 1.0 arrives it will immediately be forked to turn the unused errors into warnings, at least for debug mode.

Another situation where I think the compiler is too eager with errors: unreachable code. A bare `@panic("")` won't compile, but you can "turn off" the error by doing `if (true) @panic("")`.

Re:Zig, the Small Language by sph on Wednesday September 07, 2022 @02:22PM (#32754227)
IIRC there's already a Zig fork that turns that abomination off. I remember seeing it mentioned in that upstream issue OP mentioned.
Re:Zig, the Small Language by LAC-Tech on Wednesday September 07, 2022 @07:23PM (#32758618)
Do you remember the name or have a link?
Re:Zig, the Small Language by strager on Wednesday September 07, 2022 @08:52PM (#32759587)
Re:Zig, the Small Language by alpaca128 on Wednesday September 07, 2022 @01:58PM (#32753891)
This also makes learning Zig frustrating for people who aren't yet used to this low-level programming style. I gave up after a couple hours because it felt like I wasted half the time commenting and uncommenting code to avoid this error. People will always find ways to circumvent safety measures anyway, warnings are just fine for the developers who care.
Re:Zig, the Small Language by wyldfire on Wednesday September 07, 2022 @01:18PM (#32753408)
> I do understand the reasoning (they don't want people committing poor quality code), but this implementation just seems completely backwards to me. It breaks the natural order. It's like saying we won't let you ctrl+s until your tests pass to make sure you don't commit broken code. Stop nannying me and let me get my work done!

Could it be that this problem is due to Zig's stance on "no warnings"? It's admirable to try and partition things into strict "correct" and "incorrect" categories. But with only static information it seems like there's always things that seem a little grey.

Re:Zig, the Small Language by LAC-Tech on Wednesday September 07, 2022 @07:31PM (#32758718)
This 100%.

I love Zig. It's built on such a better foundation than any of its competitors, old or new. I've never been happier or more productive doing systems programming.

But the "no warnings" philosophy alienates developers and seriously hurts adoption. It's almost tragic that a language so impressive is going to die on this hill.

Re:Zig, the Small Language by KerrAvon on Wednesday September 07, 2022 @08:19PM (#32759262)
This sort of overopinionated design is part of what killed Phabricator. Let me customize the phucking thing a little bit. "No, we're doing opinionated design, and it's our rubber ducky."
Re:Zig, the Small Language by errantmind on Wednesday September 07, 2022 @06:06PM (#32757659)
I commented on the github issue a while back as I was frustrated with this.

I originally looked forward to splitting my projects between Zig and Rust depending on the project parameters, but because of this one seemingly small issue I will never use Zig.

That's ok, I respect them having the right to do what they want with their language but it is a little sad because I liked pretty much everything else about Zig.

Re:Zig, the Small Language by jstrong on Wednesday September 07, 2022 @12:51PM (#32753077)
100% agree, do not understand the resistance to adding a flag or other way to temporarily disable that.
Re:Zig, the Small Language by linspace on Wednesday September 07, 2022 @01:57PM (#32753887)
Refusing to compile takes the position that the compiler knows more than the developers. Or maybe are the compiler writers thinking they are the ones that know more? Maybe I'm being biased because I could consider using it in my free time and I already have enough bondage at work
Re:Zig, the Small Language by bluGill on Wednesday September 07, 2022 @02:03PM (#32753955)
When the code is "done" then I want the compiler to apply those strict checks and refuse to compile because of such issues. Every issue raised above is something that has come back to bite me in some bug later when not fixed. However like the others, I often do make a change for test purposes that I just want to see if it changes (not to be confused with fix!) the current issue, once I understand the problem better and have the right fix I will go back and clean it up, but right now I don't care about those little details when the big picture is wrong. In particular I often write code with TDD, once the current code passes the existing tests I'm going to add more code and then I'll need the thing the compiler is complaining about.
Re:Zig, the Small Language by laserbeam on Wednesday September 07, 2022 @11:33PM (#32760853)
I'll be honest, it's one of those things that sounds alienating and painful. I am only going to talk about my experience with warnings in general to explain why I support that design.

I had to work in python for a long time where code tends to be incredibly relaxed. When I switched to strict mypy typechecking at every build I became much much more productive and found and fixed dozens of bugs way earlier in development. I now am worried about all warnings and always strive to fix them.

I am also making an analogy to "not being allowed to smoke indoors" when I see these complaints. People hated those laws when they were first proposed but everyone's cool with having to do a tiny bit work for health and safety.

We'll see how communities play out, but I'm all for being rigorous.

Re:Zig, the Small Language by delijati on Wednesday September 07, 2022 @03:26PM (#32755401)
Yeah i run into the same issue, but the worst part of it, it wasn't my code i added a library and the compiler complaint unreachable code there oO
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.

Re:Zig, the Small Language by p0nce on Wednesday September 07, 2022 @03:34PM (#32755540)
That's a reason why D's default are permissive. You add this or that constraints later, as needed.
Re:Zig, the Small Language by amelius on Wednesday September 07, 2022 @01:42PM (#32753687)
Yes, the linting should be in the git-commit code, not in the compiler.
Re:Zig, the Small Language by thayne on Wednesday September 07, 2022 @11:34PM (#32760857)
My typical approach to warnings and lints is to treat them as fatal, and if there is a good reason to ignore it, specifically silence it for that specific instance, with a comment on why it is ok.

It really irks me when there isn't a way to have granular control over silencing warnings.

Re:Zig, the Small Language by ArrayBoundCheck on Wednesday September 07, 2022 @06:02PM (#32757610)
That was my problem with it. That and being mildly annoyed the creator hates tabs
Re:Zig, the Small Language by LAC-Tech on Wednesday September 07, 2022 @07:22PM (#32758605)
Thankfully the tabs thing is not meant to be permanent.
Re:Zig, the Small Language by cztomsik on Wednesday September 07, 2022 @03:09PM (#32755077)
had the same problem, if you're just prototyping, it's easy to silence that with _ = someVar

you get used to it after some time - much better than for example rust, where you have to figure out all the lifetimes, muts and generic traits before.

Re:Zig, the Small Language by pcwalton on Wednesday September 07, 2022 @06:14PM (#32757767)
> you get used to it after some time - much better than for example rust, where you have to figure out all the lifetimes, muts and generic traits before.

They aren't comparable. Everything you mentioned in Rust is necessary for typechecking. Unused variable lints aren't necessary for anything.

Re:Zig, the Small Language by cztomsik on Thursday September 08, 2022 @01:27AM (#32761532)
I understand why is that needed.

I am saying that prototyping (for me) is much easier in Zig. Some people like to define all the types (and traits) first, if it works for them then it's ok. I like to get feedback on something working as soon as possible because I'm likely a bit wrong and I will need to refine or rethink the whole thing again, rust is putting obstacles in my way, Zig is not.