Wednesday, 19 September 2012

Autocomplete & API Design

Autocomplete Rocks

As an avid Eclipse user, I love auto-complete.  It feels like it's a big, easily overlooked boost to how I program.  Not because it saves a few keystrokes here and there, but because it provides such a boon to explorability of the APIs that I use.  Essentially, I'm querying my programming environment to see what my options are.

Seeing a list of IntelliJ's top 20 auto-complete features, there are some really neat ones - chain completion is particularly cool.  IntelliJ will inspect in-scope variables several levels deep, so it's able to suggest methods of in-scope objects that I hadn't even considered.

Basically, this is a specific, but handy, limited method of querying my codebase/libraries.  I can envision more complicates ones, such as a completion that would help me with that perennial Java I/O plumbing problem of how I get from a FooWriter to a StringInputStream.  Could an IDE make a few suggestions?

Auto what?

I'm also a frequent user of Apache Tapestry, and one of the things that occasionally confounds me about it is that whenever I get rusty with a particular component, I need to look at the documentation to see what I can do with it.

Not docs accessed through my IDE, but actually busting out a web browser, and navigating through some documents meant for humans to read.  Actual essays!

This is because, in Tapestry, you write event handlers by giving an ordinary method a special name:

public void onSelectedFromMyWidget() { ... }

Tapestry uses reflection to make the association between the this method, and the "selected" event thrown by the component with the name 'MyWidget'.

But here the IDE knows nothing about the meaningful names.  There's no object to inspect, no interface that defines all the callback methods.  If I forget that the event type is 'selected' for LinkSubmit components but 'action' for ActionLink components, I have to go to the documentation.  If I don't realize I've misremembered, my event handler simply never gets passed any events.

I recently learned that HLS codes in Emacs, I wonder if this is related!