{ |one, step, back| } 1 of 1 article WikiSyndicate: full/short

The Ruby Array API   09 Dec 05
[ print link all ]

Minimalists VS Humanists—A tempest in a teapot is brewing over the proper design of a class API.

Martin Fowler VS Elliotte Rusty Harold on API Design

There’s a hot debate going on about humane API design. Martin Fowler points out that Ruby’s Array API is very rich, providing the user with lots of options when using it. Elliotte Rusty Harold responded with “A 78 method List class is about three times as bad as a 25 method List class, not three times as good.”

And so the debate rages on. Read the links on the bottom of Martin’s page for other opinions on the topic.

I was going to write a long post pointing out that java.util.List is an interface, and we like to keep interfaces short. Ruby’s Array is not an interface (Ruby doesn’t have interfaces as a language construct) but a class, and the forces that keep interfaces small don’t apply so strongly.

But … I decided not to.

Instead I’m going to point out just a small irony. Elliotte writes:

Another example: Fowler likes the first and last methods in Ruby, but list.first() is not significantly simpler than list.get(0). list.last() is perhaps a little simpler than list.get(list.size() – 1) but only because Java stupidly indexes everything from 0 rather than 1. And how often do you actually need to get the first item in the list?

But java.util.LinkedList provides:

   Object getFirst()
            Returns the first element in this list.
   Object getLast()
            Returns the last element in this list.

Interesting.

Why does Elliotte not use getFirst()? ... Because it is not available in the java.util.List interface. Java programmers typically write:

   List myList = new LinkedList();

And then use myList in their code. Since myList is declared to be a list, the getFirst() method never pops up in their completion menus.

As they say: “Out of sight, out of mind.”

 

Formatted: 07-Oct-08 03:24
Feedback: jim@weirichhouse.org