开发者

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 t开发者_StackOverflow社区ool/script which can add an unused keyword or something like that?


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?


Because...

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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜