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
out that Ruby’s Array API is very rich, providing the user with lots
of options when using it. Elliotte Rusty Harold
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:
Returns the first element in this list.
Returns the last element in this list.
Why does Elliotte not use getFirst()? ... Because it is not
available in the java.util.List interface. Java programmers
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