ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
33.74k stars 2.48k forks source link

Hacking-friendly "--sloppy" mode for Zig. #3320

Closed vi closed 3 years ago

vi commented 4 years ago

As far as I understand, Zig places great emphasis on code maintainability.

Unfortunately, restrictions required for it are at conflict with ease of development, debugging and prototyping.

I suggest to have a special Zig mode that trades code maintainability for short-term ease, ergonimics and speed of hacking. Command-line option may be --sloppy or --devmode or --lax.

Proposed rules for such mode:

josephg commented 4 months ago

Thanks - I just figured that out. (It took me a lot of searching to realise that was an option - it would be great if the compiler error suggested that as a fix).

the first is done automatically by ZLS' autosave feature

.. But, this is the worst of all worlds as far as this error goes. It means that I don't even get a compiler warning when I have unused variables. My code is silently "corrected" regardless of whether or not the fix matches my intent. If you're going to autofix code to suppress this error, zig may as well just turn the error off entirely.

rohlem commented 4 months ago

My code is silently "corrected" regardless of whether or not the fix matches my intent. If you're going to autofix code to suppress this error, zig may as well just turn the error off entirely.

@josephg Just to clarify, this is the reason why the Zig (core) toolchain has so-far taken a stance against automatic edits. The mentioned "autofix" mechanism is an opt-in feature (configuration setting enable_autofix) of ZLS (which is community-maintained). (I would assume the intent was that people would either immediately spot the autofixes, or re-read code after writing it to look for unintended uses of _ - I don't use it myself, so can't comment on efficiency one way or the other.)

josephg commented 4 months ago

or re-read code after writing it to look for unintended uses of _

This is significantly worse than a compiler warning, but I can see how it ended up this way if zls is community maintained and has a different opinion about this issue than the zig compiler authors. Sorry for temporarily hijacking the thread - and thanks for the advice. I'll give that a whirl.