<< Jim Waldo, OnJava.com, Secret Weapons, ... | Home | NFJS >>

The Desire to Make the Light Green

I just realized something.

I have been unconsciously striving to make the light green in my development in the past two years.


I have been writing unit tests for my code, just like Eric and Brian told me to. Now that I think about it, all the good engineering reasons aside, I wrote the unit tests just so that I can run then in JUnit's GUI and see the status bar turn green.

And run them I did! Sometimes I just click on the Run button again and again.


IDEA has a "error stripe" to the right side of the editor window which contains an red/yellow/green indicator showing whether a file has errors or warnings.

On my current project, all Java files are generated from a template that contains the copyright comment, marker comments like "private fields goes here" or "constructors and getInstance for singletons goes here". The template also contains two public static final fields, one named CLASS_NAME, one named logger. If the class does not actually do any logging, IDEA flags the logger as "field never used" and gives out a yellow light.

I know I need to learn to just live with it. But I can't! Every time I see the yellow light, I think about the unused logger field, wanting to delete them. But the tree is closed.


The emotional power of the green light is greater than I thought.



Re: The Desire to Make the Light Green

Ick! Templates like that are awful. IDEA is pointing out the obvious - boilerplate code is rarely actually useful and just adds clutter to your files.

It is really interesting to open up JDK source code from Sun and see how much stuff lights up yellow in IDEA. There is an awful lot of "junk code" lying around that other IDEs blissfully ignore.

Re: The Desire to Make the Light Green

Try this: Remove the logger from your source file template, and add the following LiveTemplate (I use the abbreviation "log" for this template, so when I type "log<TAB>", it expands):

private static final Log log = LogFactory.getLog($CLASS_NAME$.class);

And under "Edit Variables" for this LiveTemplate, add the variable name "CLASS_NAME", expression "className()".

Now you can add the logger only if you need it, by typing "log<TAB>" at the top of your new source file. (Note, this template assumes Commons Logging, change "LogFactory" to "Logger" for log4j).

Re: The Desire to Make the Light Green

Nice tip, Chris!

Re: The Desire to Make the Light Green

Interesting and useful ... do you try other colors?

Add a comment Send a TrackBack