Elliotte Rusty Harold is talking about a common bug you get when using C style languages:
I’ve probably wasted two hours over the last couple of
days trying to debug this line of code:
private static final QName name = new QName("valid-isbn",
Do you see the bug? I’ve even made it easier for you by
showing you just the line that contains the bug. Originally, of
course, I didn’t know this was the buggy line. The exception
was thrown somewhere completely different in the code base, but
this is indeed the buggy line.
The bug is, of course, non-obvious - the arguments are swapped.
His answer to that?
This is an example of poor API design. A method should
not have two arguments of the same type that can be confused for
each other if you can avoid it. If you can’t avoid it, then
the method should check its arguments to make sure that the right
one is in the right place; and throw an exception if it
not so much. In this case, it's a fair cop to
blame the tools . Here's how that same method would be
written in Smalltalk:
getISBNNumber: isbnString fromUrl: urlString
Which would lead to the calling method looking like:
bookName := self getISBNNumber: isbnString fromUrl: urlString
Now, given that code, what's the liklihood that the user of the method would swap the arguments? Approximately zero, but only for your larger values of zero. Showing that he anticipates (but does not fully grasp why) a complaint from Smalltalkers, he says:
Interestingly this a case where even stronger typing would have
helped, a lot; though doubtless the Smalltalk enthusiasts will
explain to me exactly how this could never have possibly happened
in their playpen; and if it did, they would have debugged it at
runtime using a piece of chewing gum, a boby pin, and a pocketknife
they got out of a Crackerjack box.
The problem has
absolutely nothing to do with the type system. Stronger typing
wouldn't help. Grabbing a better language, that makes it easy
to describe the arguments? That would help.