Re: [Eclipse] How to fix indentations.



Pseudo Silk Kimono wrote:
I would like to know how to fix my
Eclipse installation so that it does proper indentation. I seem to

Set it to use spaces instead of TABs. You should not embed TABs in Usenet source listings.

If this doesn't look good just ignore it.

That's not really good advice. The layout affects the ability, and arguably the willingness of people to read your listing with the attention needed to help you.

private static ArrayList<String> listOfFortunes = new ArrayList();
{
listOfFortunes.add("I Like food");
.... // more add() calls
listOfFortunes.add("You will be assimilated");
listOfFortunes.add("I am nothing");
}

This initialization will have the unfortunate effect of causing your fortunes list to grow each time you instantiate the object.

Why do you declare the list static but initialize it in the constructor? Wouldn't it be better to initialize the list statically, or else declare it as an instance variable?

Apropos of that collection, don't mix generics and raw types.

The variable should be of the interface type, not the concrete implementation.

It is inadvisable to build the implementation type into the variable name. "listOf" is redundant and will cause trouble if you decide later to change the implementation.

private static List<String> fortunes = new ArrayList<String>();

--
Lew
.



Relevant Pages

  • Re: Setting pointer to null!
    ... I think this debugging fetaure emerged originally ... developer forgets to initialize a variable and it accidentally ... to declare a bunch that would be "initialized" in relatively distant code. ... because you prevent the compiler from initializing them ...
    (microsoft.public.vc.language)
  • Re: "no variable or argument declarations are necessary."
    ... the compilor will allert you ... If I forget to declare several variables in C, ... >> forget to initialize several variables in Python, ... > runtime error per "forgot to initialize". ...
    (comp.lang.python)
  • Re: Replicating results
    ... gradient calculation used in a large optimization routine. ... It will make sure that if you do something like declare a variable called "x1" and use a variable called "xl" the compiler will tell you that xl was undeclared. ... Make sure that you initialize all of your variables, ...
    (comp.lang.fortran)
  • Re: question on scope of a variable
    ... G'day "Chip Orange", ... If I have a std code module and declare at the top of it, ... >to be able to initialize it, or have access to it's value if it's ... >While this compiles for me, I'm getting a runtime error that indicates the ...
    (microsoft.public.word.vba.general)
  • Re: [Eclipse] How to fix indentations.
    ... Why do you declare the list static but initialize it in the ... the method that picks and displays the random fortune, ... The variable should be of the interface type, ...
    (comp.lang.java.help)