Why are unused variables bad?

I would like to know why an unused variable is bad.

Is it because the compiler will create a larger binary? If so, is there a tool / script that can add the unused keyword or something like that?

+7
source share
3 answers

The compiler gives you warnings to hint at things that could potentially be a problem or unintentional.

Unused variables will most likely be optimized. But perhaps you intended to do something with them, in which case the compiler gratefully notes that you may have done something you did not want.

What use in a variable do you declare, but do not read or write?

+17
source

In my humble opinion, unused variables complicate the readability of your code. No matter what language you use.

+8
source

Because...

Perfection is achieved not when there is nothing left to add, but when theres nothing left to remove.

+8
source

All Articles