Thursday, May 14, 2009

On URL redirectors

Back in the day, the address resolution layer of the Internet was DNS. DNS was an open, unified, distributed, redundant, highly-engineered address resolution mechanism which hid opaque identifiers like 209.131.36.158 under the hood of nice human-readable names like www.yahoo.com. Now we have a fragmented pile of proprietary, centralized, hacked-together address resolution mechanisms which replace a nice URL like freedom-to-tinker.com/blog/felten/modest-proposal-three-strikes-print with the opaque string bit.ly/4p3vL. Progress!

Tuesday, May 12, 2009

Dynamic dispatch is just higher-order programming

Wow, this is pretty terrible coming from a Haskell programmer (via HN):

Dynamic dispatch is a scary programming technique. When you call a virtual method, you never know what might happen. This makes is [sic.] difficult to reason about such code, and code that is hard to reason about is hard to maintain.

This is true in the exact same sense that when you implement a higher-order function, "you never know what might happen". Here is a naive implementation of map in Standard ML:

fun map f [] = []
  | map f (x::xs) = (f x) :: (map f xs)

f could be bound to anything! OMG WTF BBQ!

Likewise here is a Java implementation of printList:

void printList(List aList) {
    for (Object o : aList)
        System.out.println(o.toString());
}

o.toString() could dispatch to anything! OMG WTF BBQ!

Well hold up man, let's try that in ML:

fun printList _ [] = ()
  | printList toString (x :: xs) =
    (print ((toString x) ^ "\n");
     printList toString xs);

Oh that's so much better isn't it. Or not. Basically, you will note that we had to type toString three times instead of once to achieve roughly the same effect.* Note also that this function only works over homogeneous lists; if you want a heterogeneous list, you'll have to define a union type and pack/unpack it yourself.

Object-oriented programming is a form of higher-order programming wherein related data and operations are tightly bound to each other, thus freeing you from the pain of having to wrap them up yourself, thus making it exceptionally convenient to pass data and functions together. Or, in other words, OO programming is just a functional programming idiom with lots of very convenient syntactic and semantic sugar on top**.

Now, the OO community has plenty of bad code and bad guruism bouncing around. Maybe there's somewhat less of that in the functional world. But IMO that's largely explainable by the fact that there are vastly more working OO programmers and vastly more OO code modules than functional equivalents. If the Haskell or ML community were as big as the Java community, there would be just as much terrible higher-order function spaghetti as there is terrible inheritance spaghetti today.***


* Q: Wouldn't the version using Haskell and type classes be as compact as the OO version? A: Maybe, but you'll still have to restrict the function's domain to homogeneous sequences of StringConvertable instance values. Once I hand you a heterogeneous list, you're back in the land of passing toString and packing unions. The only way to do this right is to introduce existential pack/unpack into your language, which basically amounts to introducing a slightly crippled object system with additional syntactic overhead.

** In particular, making super sends and self sends work correctly without OO sugar gets messy. OTOH, conversely, the object-oriented programming languages in common use make certain other kinds of functional programming idioms somewhat baroque — for example, Java's lack of a compact syntax for anonymous functions is a huge pile of Lose — but that's a discussion for another day.

*** In fact, I strongly suspect that with a fair number of kids today thinking that Haskell is the new hotness, that community's in for a rude awakening as they realize that Haskell's going to require style guides and "Haskell annoyances" books and assorted baroque frameworks in order to allow programmers of average ability to assemble software of similar complexity to that commonly assembled in Java today.

Saturday, May 09, 2009

Robert Martin + Ruby = ughhhh

A recent talk by Robert Martin on Smalltalk and Ruby is generating a lot of buzz today. Now, I just gave you the link to the talk, but don't take this to mean that I think you should watch it. I had a whole long writeup-in-progress about all the different kinds of Wrong embodied by this talk and its reception. But there was so much to explain, so many kinds of Wrong, that I just gave up.

Instead, I'll give you an abbreviated summary of a few reactions:

  • Holy shit, Martin is long-winded. A talk of this length with so few ideas* is offensively disrespectful of its audience's time.
  • Estrogen = weak and insipid? Really? Without a hint of irony? And not a raised eyebrow in the room? WTF?
  • The fact that many Ruby hackers seem to think that this was a good talk shows how bad that community's taste is.
  • Twitter's 140 characters are completely inadequate for discussing a subject like this; on the other hand it's a great medium for saying AOL! Which is, I suppose, one reason it has prospered.

I write this post mostly to record how depressed I am that software guruism of such low quality seems to be so popular.

If you want to wash the ugly taste of Martin out of your mouth, I recommend this interview with Leslie Lamport. Ruby hackers have esprit de corps and throw big buzzworthy conferences, whereas Lamport is merely a genius. Guess what the kids end up learning today.


*If you care at all, his entire argument can be summed up in a few sentences as follows:

  • Smalltalk is much more expressive than C++.
  • However, Smalltalk does not "punish you for making a mess"; i.e. you can easily write software that is intricate to the point of being incomprehensible. This is why Smalltalk failed.
  • Test-driven development can provide the discipline which stops the same thing from happening to Ruby.

As I've noted, I think this argument's wrong in so many different ways that it exhausts me mentally even to try to enumerate them all. But just as one angle of attack, note that of the suggested causal factor is false of many failed languages, and true of several popular ones. Forget about correlation not implying causation; I claim that in this case even the correlation is low. Furthermore, long-lasting popularity is so rare for programming languages that it is a fool's game to talk about why unpopular languages never became popular; it's much more fruitful to seek the very rare combination of characteristics common to successful languages.


p.s. UPDATE 8pm: What a relief, lots of other people thought the talk was b.s. too. See J. Robertson of Cincom

UPDATE 2017-10-06: Fixed some linkrot.

Saturday, May 02, 2009

Condoleeza Rice: The rationalizing, supercilious face of evil

When C. Rice retired from her life of crime, she decided to become a professor at Stanford. Unlike, say, Bush's retirement to his ranch, this position entails occasionally being confronted by young and idealistic students about her past:

Evil has many faces and this is one of them. It is a face that blandly smiles upon horrific acts and later spins an endless stream of moral justifications from whatever flimsy fiber is conveniently available. A morally whole human being, upon learning that prisoners had been subjected to controlled drowning hundreds of times due, in part, to actions that she had participated in, would acknowledge the horror, accept some kind of responsibility, express some kind of regret.

Rice does no such thing. She has entirely expunged any feelings of guilt. Any residual sense that she might have been wrong has been entirely conquered by her narcissistic need for self-justification. Observe her demeanor, and her language ("dear", "do your homework"): Not only does she feel that the student's wrong, she feels that it's vaguely unfair that people even think she did something wrong, and especially unfair that young uncredentialed whippersnappers outside the circle of power get to question her conduct.

Forget about the tortured prisoners; what about Condoleeza's suffering? Huh? It puts one in mind of an old Fafblog post.

As to the substance of her argument, it is nonsense, of course. It rests upon the twin assertions that

  • since the Bush administration orders were phrased so as to authorize only interrogation techniques cleared by the Justice Department, they were ipso facto legal; and
  • Chewbacca was a wookie — that is, lots of irrelevant misdirection about stuff like the uniqueness of al Qaeda (about which, in particular, A. Serwer has the best answer).

The first defense opens an infinitely large loophole in the rule of law — appoint your pet lawyers to Justice, and then trample on the law all you want! Even if you could, by some reading of the relevant legal texts, construct a legal theory that reached this conclusion, you would not want this reading to be the one that prevails in governance. To establish such a precedent would be disastrously bad as a matter of public policy. It would be much better to construct a different reading, one in which the most powerful people are actually constrained by the law.

If Rice were a dispassionate observer — if the very same quality of mind were transplanted into someone who had no personal or professional ties to the Bush administration or the conservative movement — it is hard to believe that an idea so patently bad and stupid would get past her. But self-interest and tribalist instincts are powerful motivators. And I suppose you go to war with the flimsy legal arguments you have...

...and not the ones you wish for.


Incidentally, judging just from the first video, you might conclude that Rice "wins" the confrontation. And in theatrical, TV terms she does: at the end she fishes out a gotcha question about Guantanamo which the student cannot answer. This was a foregone conclusion. It's not really a fair fight: Rice has had a long time to practice her legalistic justifications for her actions. These students are newbies. Her ability to fend off some callow undergrads demonstrates that an expert in any given subject can extemporaneously ejaculate a convincing wad of noise to defend anything.

But let's examine the two ways she deflects the student's question.

First, she goes on at length about Guantanamo not being a site for interrogations. This is correct; the torture was conducted by the CIA in locations around the world that have not been disclosed, although they're outside the United States. According to ABC News, one likely candidate is abandoned Communist military bases in Eastern Europe. Which is so much better than doing it in Guantanamo! But Rice doesn't mention any of that. The student's confusion regarding interrogation vs. indefinite detention is actually convenient for her, as it allows her to completely change the subject away from torture without being obvious about it.

Second, regarding Rice's gotcha question about putting the Guantanamo prisoners on trial: the answer to Rice's question is that federal courts halted the trials because they concluded that the trials were being conducted illegally. Or, more euphemistically, the tribunals convened by the Bush administration had failed to satisfy the requirements necessary to be called proper ("competent") military tribunals. Or, less euphemistically, Rice's pals setup some kangaroo courts; and she wants this fact to excuse her for holding thousands of mostly innocent people in concrete cells for years on end without providing them timely legal recourse.

Theatrically, Rice won the confrontation. But the cold light of later reflection exposes her rejoinders as total trash. The medium of video is not well-suited to reasoned argument.