Varargs: Java is finally giving some conveniences Wearing a “Real Name” badge
Aug 06

IDE Feature: Show me a pared down view of staticly typed code

Tech Add comments

I love IntelliJ IDEA, and Eclipse is good too. Tools such as these are so good that I often here:

My IDE takes care of the verbosity of Java

This sounds great. However, it is only really helping in the WRITE stage of your development. Sure, it is great that you can say “Give me a New Foo Pattern” and a tool can then create 2 interfaces and 3 implementation classes that make up that pattern.

The problem is that we aren’t getting as much help in READING the application, and it makes it complicated to understand.

Java has a lot of noise that is muddled into the meat of the logic.

Take the examples from James and Rod’s Groovy presentation at JavaOne:

Java

public class Filter {
public static void main( String[] args ) {
List list = new java.util.ArrayList();
list.add( "Rod" ); list.add( "James" ); list.add( "Chris" );
Filter filter = new Filter();
List shorts = filter.filterLongerThan( list, 4 )
for ( String item : shorts )  { System.out.println( item ); }
}
public List filterLongerThan( List list, int length )  {
List result = new ArrayList();
for ( String item : list )  {
if ( item.length() <= length ) { result.add( item ); }
}
return result;
}
}

Groovy

list = ["Rod", "James", "Chris"]
shorts = list.findAll { it.size() <= 4 }
shorts.each { println it }

I find it a lot easier to grok what is going on in the second example.

One IDE feature that could potentially help, is if I could click on an icon/hit a keystroke which ran the function: "Hide Fluff"

This would hide a lot of the modifiers (public/private/etc) and the static typing. It would all of course be there, and the IDE can make use of that, but it would enable a view on your code which is more of the meat.

2 Responses to “IDE Feature: Show me a pared down view of staticly typed code”

  1. J Yu Says:

    just to point out that, in 1.5, the first line can be done as

    List list = Arrays.asList(”Rod”, “James”, “Chris”);

  2. Randomness Says:

    Stuck In A Mindset

    This is a great example of getting stuck in a mindset. A piece of very poorly written Java code is presented followed by a much shorter piece of Groovy code and Groovy is declared the winner. The original Groovy: list…

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: What is the number before 3? (just put in the digit)

Loading...