#How do I allow unused variables for dev'ing

1 messages · Page 1 of 1 (latest)

bright rock
#

I am currently getting into Zig and the constant erroring of zig because of unnused variables or parameters is driving me crazy.
I have already read, it is unsafe and can lead to bugs, but I just wanna develop and can clean up later in the final build if I missed anything. But it is so annoying if I have to use it in a weird way in order to see if my code works, for example if I have a partial function written I wanna test if it works to that part and just print some data, but it is prohibiting.
A warning would be fine to grab my attention but why stop me from developing my code?

light parrot
#

wouldnt be much of an error if it didnt stop you

bright rock
#

oh

#

ment to write warning

light parrot
#

theres no way to disable it, either get into the habit of not declaring variables before you use them or use _ = foo; to silence it

#

if you use zls it has the ability to do that for you on save

bright rock
#

That seems okay, but I read that a --sloppy thing was like uh a thing, or did I misread?

#

Or something like it

light parrot
#

there was a proposal but it never happened

bright rock
#

Can't find it in the suggestion tho

bright rock
light parrot
#

you could 🤷‍♂️ but its also explicit so you can search for occurrences of it, zls also adds a hint diagnostic when it does it for you

wild vapor
light parrot
#

that too

wild vapor
#

At least by ZLS, like no one's uncle said

bright rock
#

Ahh okay 🤔 I guess this is fine, still seems a bit annoying will see if I can get used to it 😄

runic spoke
#

it's not hard to bypass, but the compiler does detect the most trivial case

stoic ingot
left atlas
#

If you're "cleaning up", it's not your final build. "Just a little cleanup" is notorious for generating or exposing bugs. You're not done until you're done.

maiden oak
#

I've taken more to not living too far in the future while coding, and I haven't seen this error in ages. I code for what I know, one specified thing at a time.

hard ibex
#

the vscode zig extensions allows you to set a setting where it will do _ = variable; // autofix

so you dont have to worry about unused variables

hard ibex
# maiden oak I've taken more to not living too far in the future while coding, and I haven't ...

hard to believe, I recently realized i became what I hate. A person who codes for minutes on end without even running the code once. Besides it not working in my favor at all, it also demotivates me and makes me less productive overall.

For me its way better to run the code after very small steps/changes, oftentimes even leaving some function parameters empty for now to see if the rest works as expected. This way there is no way around unused parameters but even without that I would run into them quite often, the autofix is a must for me

celest pine
#

Admittedly, It can be a little annoying to not be able to do a quick “comment this out” and see what happens, or “add code 5 lines at a time and verify” because of the unused variable problem. But it does force cleaner code in the long run. So I kind of have a love/hate relationship with this aspect of zig.

As much as I hate it, it’s probably better than rust in this regard, in rust is end up building up a few unused variable warnings over time and end up with piles of ignored warnings.

#

Personally I think a good compromise would be a flag to allow quick debug runs that works in Debug but not Release* modes.

This would allow quick tests while coding, but add a hurdle preventing release with lazy code.

stoic ingot
#

This would allow quick tests while coding, but add a hurdle preventing release with lazy code.
then the next lazy solution is releasing a debug build

kind dragon
#

Tbh what we need is a language server that can help a tool refactor backwards, commenting out unused code