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

后端 未结 16 2219
梦谈多话
梦谈多话 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 05:46

    What about the case such as:

    public static final int NORTH = 0,
                            EAST = 1,
                            SOUTH = 2,
                            WEST = 3;
    

    Is that considered bad practice as well? I would consider that okay as it counters some of the points previously made:

    • they would all definitely be the same type (in my statically typed Java-world)
    • comments can be added for each
    • if you have to change the type for one, you probably have to do it for all, and all four can be done in one change

    So in an (albeit smelly code) example, is there reasons you wouldn't do that?

提交回复
热议问题