R
Rhino
I've received some criticism recently with regards to the approach I use to
initializing variables so I'd like to throw this issue out to the whole
group so that I can learn more about the pros and cons of the approach I am
using....
Basically, I initialize pretty much every variable as I declare it, just to
be sure it has some kind of value right away. That initial value is
typically a zero for a number or a null for an object. Some recent
criticism questioned this practice so I thought I'd review some of the
material that helped get me in that habit in the first place.
The Java Tutorial, specifically
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html,
says that, although non-local variables always get a default value anyway,
relying on that "is generally considered bad programming style". They also
point out that local variables are never assigned values in advance and
will cause compile-time errors if an unitialized variable is accessed.
Now, the Java Tutorial is aimed at Java beginners so this particular advice
may not be appropriate for people with more experience. I consider the
experts on this group a pretty advanced bunch so how do you feel about this
advice?
initializing variables so I'd like to throw this issue out to the whole
group so that I can learn more about the pros and cons of the approach I am
using....
Basically, I initialize pretty much every variable as I declare it, just to
be sure it has some kind of value right away. That initial value is
typically a zero for a number or a null for an object. Some recent
criticism questioned this practice so I thought I'd review some of the
material that helped get me in that habit in the first place.
The Java Tutorial, specifically
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html,
says that, although non-local variables always get a default value anyway,
relying on that "is generally considered bad programming style". They also
point out that local variables are never assigned values in advance and
will cause compile-time errors if an unitialized variable is accessed.
Now, the Java Tutorial is aimed at Java beginners so this particular advice
may not be appropriate for people with more experience. I consider the
experts on this group a pretty advanced bunch so how do you feel about this
advice?