Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are unused variables bad?

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?

like image 595
klefevre Avatar asked May 28 '11 22:05

klefevre


2 Answers

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?

like image 84
Joey Avatar answered Sep 28 '22 09:09

Joey


Because...

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

like image 30
R.. GitHub STOP HELPING ICE Avatar answered Sep 28 '22 09:09

R.. GitHub STOP HELPING ICE