Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #21679

Re: unused statics?

Newsgroups comp.lang.java.programmer
Date 2013-01-24 17:16 -0800
References <263f14ba-8542-4ec5-9e23-0a91da46e62d@googlegroups.com> <8cfbd2b9-1941-45d1-865b-1a7b5f9c515e@googlegroups.com> <51019d7f$0$291$14726298@news.sunsite.dk> <oaSdnUTRN-cXOZzMnZ2dnUVZ_sKdnZ2d@earthlink.com> <5101bec0$0$283$14726298@news.sunsite.dk>
Message-ID <8b069e2e-93d3-4356-b2ae-23408c392228@googlegroups.com> (permalink)
Subject Re: unused statics?
From Lew <lewbloch@gmail.com>

Show all headers | View raw


Arne Vajhøj wrote:
> Patricia Shanahan wrote:
>> Arne Vajh�j 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 specifically 
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 emphasize 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

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

unused statics? bob smith <bob@coolfone.comze.com> - 2013-01-24 12:23 -0800
  Re: unused statics? Lew <lewbloch@gmail.com> - 2013-01-24 12:31 -0800
    Re: unused statics? Arne Vajhøj <arne@vajhoej.dk> - 2013-01-24 15:45 -0500
      Re: unused statics? Patricia Shanahan <pats@acm.org> - 2013-01-24 13:15 -0800
        Re: unused statics? markspace <markspace@nospam.nospam> - 2013-01-24 13:54 -0800
        Re: unused statics? Arne Vajhøj <arne@vajhoej.dk> - 2013-01-24 18:07 -0500
          Re: unused statics? Lew <lewbloch@gmail.com> - 2013-01-24 17:16 -0800
            Re: unused statics? Arne Vajhøj <arne@vajhoej.dk> - 2013-01-24 20:31 -0500
              Re: unused statics? Arne Vajhøj <arne@vajhoej.dk> - 2013-01-24 20:35 -0500
            Re: unused statics? Patricia Shanahan <pats@acm.org> - 2013-01-24 17:38 -0800
            Re: unused statics? Magnus Warker <magnus@mailinator.com> - 2013-01-25 05:29 +0100
            Re: unused statics? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-01-25 08:42 +0000
          Re: unused statics? Gene Wirchenko <genew@telus.net> - 2013-01-25 09:36 -0800
            Re: unused statics? Arne Vajhøj <arne@vajhoej.dk> - 2013-02-24 17:55 -0500
  Re: unused statics? Arne Vajhøj <arne@vajhoej.dk> - 2013-01-24 15:43 -0500
  Re: unused statics? Roedy Green <see_website@mindprod.com.invalid> - 2013-01-26 02:53 -0800
    Re: unused statics? Arne Vajhøj <arne@vajhoej.dk> - 2013-01-26 16:37 -0500

csiph-web