Reputation: 8735
I would like to know why an unused variable is bad.
Is it because the compiler would create a bigger binary? If yes, is there a tool/script which can add an unused
keyword or something like that?
Upvotes: 9
Views: 5372
Reputation: 51
at somepoint memory is limited. Memory stack get full and overloaded when there are unused variables in the code. Compiler will take more time to run the code. So as for the sake of memory consumption and memory optimisation unused variables are bad.
Upvotes: 0
Reputation: 1738
In my humble opinion, unused variables complicate readability of your code. No matter what language you are using.
Upvotes: 10
Reputation: 215457
Because...
Perfection is reached not when there’s nothing left to add, but when there’s nothing left to remove.
Upvotes: 12
Reputation: 354734
The compiler gives you warnings to hint on things that could potentially be a problem or unintentional.
Unused variables will be optimized away most likely. But maybe you intended to do something with them – and in that case the compiler helpfully notes that you may have done something you didn't want.
What's the use in a variable you declare but neither read from nor write to?
Upvotes: 21