Why do you not declare several variables of the same type on the same line?

后端 未结 16 2252
梦谈多话
梦谈多话 2020-12-06 05:41

Why is it bad practice to declare variables on one line?

e.g.

private String var1, var2, var3

instead of:

private          


        
16条回答
  •  情书的邮戳
    2020-12-06 06:06

    Generally it is, for the version control and commenting reasons discussed by others, and I'd apply that in 95% of all cases. however there are circumstances where it does make sense, for example if I'm coding graphics and I want a couple of variables to represent texture coordinates (always referenced by convention as s and t) then the declaring them as

    int s, t; // texture coordinates

    IMHO enhances code readability both by shortening the code and by making it explicit that these two variables belong together (of course some would argue for using a single point class variable in this case).

提交回复
热议问题