Re: unused statics?
Arne Vajh=F8j wrote:
Patricia Shanahan wrote:
Arne Vajh=EF=BF=BDj wrote:
Lew wrote:
Why was it assigned its default value redundantly?
Sometimes it improves readability.
Not this time. Was it the OP's intention? Why not let the OP answer?
I often do that as a note to myself. It means I do expect to use the
Was that the OP's intention? Why not let the OP answer?
initial value, have considered what the initial value should be, and
have chosen 0.
In general, I agree. That didn't seem to apply here, so I asked the OP spec=
ifically
why in this case they did that.
I think that it is easier to read code that are consistent
in initialization.
A class where all fields are initialized in declaration,
a class where all fields are initialized in constructor or a
class where all fields get default value is easy to understand
in my opinion.
If 1/3 of fields are are initialized in declaration, 1/3 in
constructor and 1/3 get get default value then the reader will
spend the first 10 minutes trying to guess what the developers
reason for doing so is.
There are engineering reasons for each of the three choices. Sometimes
those reasons vary within the same class. So then you use comments to
explain the divergence. Whenever I deem it worthwhile to take the tiny
performance hit of redundantly assigning the same value to a member twice,=
I comment why it's done.
So I think you'd find that readable, too.
Here's why you need more than one way to do things:
public class Foo<T>
{
private final Class<T> rttt;
private boolean initialized = false; // explicitly initialized to empha=
size the logic
private Bar bar;
public Foo(Class<T> rttt)
{
if (rttt == null) {throw new IllegalArgumentException("null rttt");=
}
this.rttt = rttt;
}
public void setBar(Bar bar)
{
this.bar = bar;
}
public Bar getBar()
{
return bar;
}
}
I see no readability problems with this.
--
Lew