Steve Jenson's blog

Self-documenting interfaces and having nice tools.

Self-documenting interfaces and having nice tools.

I used to prefer dynamic languages (specifically Python, Common Lisp, and Ruby) over Java for my spare-time coding projects. That's changed recently and I've come to realize it's because of generics and the smart for-loop in Java 5.

Since Generics arrived in Java, my code has a much cleaner feel to it. Imagine a class for generating Atom feeds. Instead of the Python code:

    class Feed:
    [...]
      def get_entries():
        return entries
    
In Java, the method signature would tell me everything
    interface Feed {
      Iterable<Entry> getEntries();
    }
    

Now I know immediately that what I will be getting can be shoved through a smart for-loop and the entries worked over like so:

    for (Entry e: getEntries()) {
      doSomething(e);
    }
    

I had a good idea that the Python code would return a List (because I can see the return statement) but I'd have to run my tests to be sure it worked. With Java 5, I have a better chance at build self-documenting interfaces. I really like that.

I should probably also admit that IntelliJ IDEA has completely changed how I program in Java. I used to code with the following steps:

  1. make changes
  2. compile and wait forever.
  3. read compiler errors
  4. fix
Now it's more like:
  1. make changes
  2. look at the sidebar for red
  3. see red, go directly to the error
  4. fix

Same amount of steps but because of incremental compilation it's a small fraction of the former time and I never leave my editor.

I'm sure I'll write some gushing blog posts about IDEA and Java 5 in a few weeks. Papa's got a new bag.

(Sorry, that's the last time I'll call myself "Papa")

# — 29 September, 2005