Electric Josh

Tuesday, July 23, 2002

Fielded several calls today from my excellent colleague, who is typically a Python programmer, and helped him through some of the more horrible corners of Java's Collections class and its various friends. The worst of the several stupid Javaisms he was running up against was the following:

// The following code is obviously trying to get
// a list of widgets and then convert it from
// a Collection of widgets into an array of Widgets.
// (The fact that it's necessary to do this at all
// also annoyed my excellent colleague.)
Collection someList = getAListOfWidgets();
Widget[] theWidgetArray = (Widget[])someList.toArray();

Simple, right? Just take the Collection that contains a bunch of Widget objects, call toArray() on the Collection, downcast (ack!) the result from Object[], which toArray() actually returns, to Widget[], since we know that everything in someList is actually a Widget.

The code compiles beautifully and promptly fails at runtime with a ClassCastException, which is ridiculous because we just jumped through all these hoops so that we could get a Widget[] instead of an Object[].

Turns out that the proper call on the last line is actually:

// The following code is obviously trying to get
// a list of widgets and then convert it to
// a Collection of widgets into an array of Widgets.
// (The fact that it's necessary to do this at all
// also annoyed my excellent colleague.)
Collection someList = getAListOfWidgets();
Widget[] theWidgetArray = (Widget[])someList.toArray(new Widget[0]);

In other words, there's downcasting going on even deep inside the language's built-in collection routines. Remember that the whole point (much of the point, anyway) of using a strongly typed object-oriented language is that you don't have to downcast. A more normal language, like Python, would write the above code in the following fashion:

# The following code is obviously trying to get
# a list of widgets and then convert it to
# a Collection of widgets into an array of Widgets.
someList = getAListOfWidgets()

Now, isn't that nicer? #

...

Here's a great example of what the Cluetrain guys must have been talking about when they asserted that we are not eyeballs, and what they must have been pointing out to us in the third of their 95 theses:

Conversations among human beings sound human. They are conducted in a human voice.

This Times article is all about large companies' inability to make money hand over fist in quite the automatic fashion they had thought fat pipes into peoples' homes would allow. Without even a hint of irony, it talks about us regular people using a language that, while recognizable as English, isn't something any person would actually say. It contains gems such as:

Of course, not everyone wants to be so proactive about their media consumption.

You can't make this shit up. The loudest example of this stupid business-speak appears in the main thesis of the article:

For consumers, that may be a good thing. But for media companies looking to the Internet for profits, it remains a frustrating reality.

The only time that the word "customer" appears in the article is in this description of who's getting sued by the large entertainment/media outfits:

The major entertainment companies are all suing Sonic-blue, the maker of a device that allows customers to record shows and trade them over the Internet.

So these companies sue their "customers". Everywhere else, it's "consumer". Awesome. #

© 2001-2002, Josh Daghlian. All rights reserved.