Why are unused variables bad?

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?


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


Because...

Perfection is reached not when there’s nothing left to add, but when there’s nothing left to remove.