My thoughts as an enterprise Java developer.

Wednesday, October 05, 2005

Declaring variables

A pet peeve of mine is when a variable is declared way before it is needed. It is much easier to understand a piece of code if a variable is declared just before it is needed. That immediately tells me that it isn't used anywhere before that or in any wider scope.

I also find it annoying when a variable is declared with a null value and them immediately assigned a value.

String value = null;
value = "hi";

should be:
String value = "hi";

Not that one reason to do that the first way is if the second way would create a line that is too long.

No comments: