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

conventions, language-agnostic, refactoring

Solution

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.

Problem

Why is it bad practice to declare variables on one line? e.g. ``` private String var1, var2, var3 ``` instead of: ``` private String var1; private String var2; private String var3; ```

Original source