Ian Bicking: the old part of his blog

The unbridled humanity of APIs

Marin Fowler raised quite the storm with a rather modest post about humane interfaces, which was responded most notably with a critique from a Java guy, and a counter from the Smalltalk guy. But I think the Java guy has a point: 78 methods on your list objects isn't good. Less methods is good. Unless the result is stupid. Now, let's be honest here, Java is stupid. Dumb, idiotic, maybe written by people who aren't programmers; I just don't know how else to make sense of it. list.get(list.size() - 1) should be embarrassing. list.last or list[-1]? I think [-1] reads well enough, and fits into a very elegant set of functionality involving slices and whatnot. But I also think list.last is entirely justifiable. OTOH, list.get(0) isn't embarrassing, so list.first isn't as compelling. And the nitems method he points to really seems overboard. There needs to be a limit somewhere. 2.years + 3.days ... I don't know if I can really get behind that (BTW, that's not built in to Ruby, but it can be extended to do that).

Maybe an interesting parallel is 0 vs. 1 indexing. 1 clearly seems more humane. I personally count starting from 1. I'm naturally inclined to index from 1. Languages go both ways on the choice.

But, while 1 indexing is more humane, 0 indexing is consistent with a set of useful properties. Programming is both narrative and mathematics, and when the two are in conflict it's hard to say which one is right. But experience can tell us which is right. 0 is right.

Mathematicians are inclined towards minimalism. But mere minimalism does not make something mathematically sound or reasonable. Mathematics is a sensible argument for 0 indexing. But mathematics has nothing to say about the number of methods on containers.

Not accounting for good container handling in your language is stupid. Stupid, stupid, stupid. If you are clever, you can make it seem like container handling just falls out of your more fundamental constructs. Smalltalk does this well. But don't be fooled -- an otherwise similarly elegent system that didn't work well with containers would have been discarded. The Smalltalk designers were playing the same tricks mathematicians play; when you look at a mathematic proof you think how elegent, how simple, and how indecipherably attained. If I strive for simplicity, work from just a few axioms, will I achieve the same thing? No! Because there's lots of notes and failed attempts and crude proofs the mathematician didn't show you (it would be fascinating to see what Smalltalk 76 actually looked like). Java is like someone looking at a proof and thinking that they will write down theorems starting from simple axioms and get something good out of the other end. But they didn't realize that the (talented) mathematician deduces an interesting outcome and creates the proof as a bridge to that outcome. Missing this, the Java designers created something stupid and crude. They created something that had all the trappings of good design, with none of the outcomes that drive good designers.

Of course Smalltalk indexes from 1, so no one gets everything right.

Created 08 Dec '05
Modified 09 Dec '05

Comments:

Whatever your feeling is about Java, saying it is stupid is really not a smart thing to say. You spread oil on the flames. Instead of trying to decrease the gap between the two communities you just end up giving a bad image of the Python community to the Java world. Now that is stupid IMO.

# S.

source
// "stupid" seems an appropriate description for a language that can't split a string...
// To be honest, I can't figure out how they screwed this up.  I'm trying
// to imagine what the underlying split() code looks like, and I can't picture it.
public class stupid
{
    public static void main (String[] args)
    {
        System.out.println("1:2:3".split(":").length);
        System.out.println(":2:3".split(":").length);
        System.out.println("1:2:".split(":").length);
        System.out.println(":2:".split(":").length);
        System.out.println("1::".split(":").length);
        System.out.println("::".split(":").length);
    }
}

C:\tmp>javac stupid.java && java -cp . stupid
3
3
2
2
1
0

Compare:
>>> print len("1:2:3".split(":"))
3
>>> print len("1:2:".split(":"))
3
>>> print len(":2:".split(":"))
3
>>> print len("::".split(":"))
3
# msw

I think sometimes people mistake poor language design for problems with static typing. One class of problems is structural, and represents specific priorities with respect to the programmer and architect. But many parts of Java just show poor language design. Not giving containers (quality) first class syntax is just a design problem, there's nothing fundamental about it. So I call it stupid, because I think containers are pretty damn useful.

# Ian Bicking

> Of course Smalltalk indexes from 1, so no one gets everything right.

"You know, for kids."

# anonymous

I just assumed that the 'nitems' thing was there because Matz used it more than once in some code he was writing.

# Piers Cawley