为什么不在同一行上声明多个相同类型的变量? [英] Why do you not declare several variables of the same type on the same line?
本文介绍了为什么不在同一行上声明多个相同类型的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么在一行上声明变量是不好的做法?
Why is it bad practice to declare variables on one line?
例如
private String var1, var2, var3
代替:
private String var1;
private String var2;
private String var3;
推荐答案
我认为有多种原因,但是它们全都归结为第一个原因是可读性较差并且更容易失败,因为单行的作用更多比一件事.
I think that there are various reasons, but they all boil down to that the first is just less readable and more prone to failure because a single line is doing more than one thing.
所有这些都没有真正的收益,而且您不告诉我,发现两行节省的空间才是真正的收益.
And all that for no real gain, and don't you tell me you find two lines of saved space is a real gain.
这与您拥有时发生的事情类似
It's a similar thing to what happens when you have
if ((foo = some_function()) == 0) {
//do something
}
当然,此示例比您的示例差很多.
Of course this example is much worse than yours.
这篇关于为什么不在同一行上声明多个相同类型的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文