Unused variables, better as error or warning?
bearophile
bearophileHUGS at lycos.com
Fri Aug 20 13:54:24 PDT 2010
Walter Bright:
>Having such be errors (or warnings) makes for a very annoying experience. For example, when you're commenting out code trying to find a problem, or when you're generating D source code from some DSL, etc., having unused variables or assignments happen often.<
In this answer assume here you are talking about unused variable warnings (UVW). And your conclusion that UVW are bad is wrong.
I have appreciated UVW in all languages where they were presents, and I'm using C for some time. I also know you have a long C experience. (So are you refusing UVW because the DMD back-end makes it hard to implement them? I think of you as an honest person, so I refuse this hypotesys).
UVM are optional, so if you compile code when you have some commented out code, you are free to ignore the warnings (that can't be many if the code is well written) or you are free to deactivate warnings in this specific situation.
In the case of automatic generation of D code, this case is quite less common than normal code where the UVW can help you spot bugs and keep your code clean and tidy. And if this becomes really a problem a pragma can be created to allow you to disable UVW where for simplicity you generate code that may contain unused variables.
So if you give me this warning, you are free to keep it always deactivated in all your future D programs :-)
Bye,
bearophile
More information about the Digitalmars-d
mailing list