crazed monkey

Archive for December, 2002

RSS

Spirited Away

Frank posted his review of Spirited Away last night, and I feel that I need to respond to the following comment:

Ironically, Ian and Vic walked out of there claiming to have found it incomprehensible. This astonishes me - this had the most coherent, albeit simple, plot of any anime I’ve ever seen. Savages.

It wasn’t that I found the plot incomprehensible, just that I suffered severe whiplash from the plot twists pulled out of Miyazaki’s ass. In creating Spirited Away, it’s as if Miyazaki started with the end result (young girl gains strength and learns some lessons about good and evil and the blurred boundary separating them by experiencing life in an imaginary world) and then hired a five-year old with an ether addiction to fill in the plot points. Naturally, I realise that this is the same premise behind Alice’s Adventures in Wonderland, but I don’t much like that story either. Tales of morality do not appeal to me.

Don’t get me wrong, the movie wasn’t all bad. The animation and details were incredible, each scene more inspiring than the one previous. The characters were very well done with easily identifiable personalities, although Haku was a little wooden. I liked how nobody in the movie was truly evil and few were truly good. Even Yubaba, the witch who runs the bath house where much of the movie takes place, had her good points. I would rate Spirited Away higher than Princess Mononoke, Miyazaki’s previous work, on the characters alone.

Posted on December 18th, 2002 in culture, movies - No Comments »

XPath makes XML parsing easy

I’ve been using XPath and XQuery to parse my XML documents as of late and, wow, does it ever make parsing easier. For instance, suppose I wanted to collect elements which had a bar attribute of “baz”. Using The Mind Electric’s Electric XML without XPath support, I would have to do something like the following, assuming document is an instance of electric.xml.Document:

Elements fooElements = document.getElements( "foo" );
while( fooElements.hasMoreElements() )
{
    Element fooElement = fooElements.next();
    Element barAttribute = fooElement.getAttribute( "bar" );
    if( barAttribute != null && barAttribute.equals( "baz" ) )
    {
        // Handle the foo elements
    }
}

With XPath, this is reduced to one line:

Elements fooElements
        = document.getElements( new XPath( "foo[@bar='baz']" ) );

Aside from the shorter code, another upside is that all optimisations are left to the XML library. The second way is at least as fast as the first, unless the underlying code is very poorly written, and is just as easy to maintain. A short comment removes any confusion to those new to XPath. Then again, the first piece of code wouldn’t be immediately obvious without the same comment.

The downside to having XPath available is the quest to express any request for XML elements in a single expression. While before I grudgingly accepted the non-XPath way of retrieving XML elements, I now find myself poring over the spec to find that one expression which will make my life easier.

Posted on December 16th, 2002 in computers, programming - No Comments »

I have no inner geek

In case there was any doubt as to my level of geekiness after reading my most recent tirade, Vic wanted me to mention that my background graphic was drawn in XFIG, a vector-based drawing program for systems running X Windows, and imported into The GIMP where a canvas filter was applied to obtain the finished image. A second filter was applied to the faded background image, which was blurred and had its contrast reduced.

I get confused when people talk about their “inner geek”, either implying that they only let it out on special occasions but otherwise keep it locked up tight, or that somehow having one gives them a slight edge with a touch of cool. These people are either closet geeks, suppressing their true urges, or are poser wannabes. I have no inner geek and neither do most of my friends, who are geeks in some form or another, be it computer, music, science, art or other. Geeks are people who have clear interests and truly care about them, mostly to excess. And, no, that doesn’t include drugs, alcohol or, regrettably, self image.

Posted on December 15th, 2002 in meta, site - No Comments »

Further separating content and style

To further separate content and style in my weblog, I have eliminated the use of the <tt> and <i> HTML elements. Any use of the <tt> element has been replaced with one of <code>, <samp> or <var> when referencing computer code, output or variables, respectively. I am a little fuzzy on where text which delineates an XML element or a method name fits within those three elements and so I am surrounding them with <code> for now. Since I used the <i> element sparingly, my only uses were when referencing a title of a work, or when quoting within a <blockquote> element. Instances of the latter have been eliminated as this is why stylesheets exist, while instances of the former have been replaced with <cite>.

Why am I doing this? I do not want to force browsers to render blocks of code in a certain way. If some users prefer their book titles to be underlined, who am I to say that shouldn’t be possible? If someone likes computer code, inlined or not, to be rendered with a grey background, so be it. Furthermore, as someone who has written programs to scrape useful information out of HTML, I appreciate the need to be able to easily do so, which is why my weblog is strict XHTML1.0.

My name is Ian Stevens, and I support the segregation of content and style.

Posted on December 15th, 2002 in meta, site - No Comments »

Java and read timeouts

We were encountering a problem in the server code at my company whereby read() requests on a stream were blocking and never returning. This was causing periodic data retrieval within threads to hang, which would eventually eat up all available threads and lead to stale data. I tried creating a watchdog thread which would periodically loop through the data retrieval threads, determine their execution time and then call Thread.interrupt() if that value exceeded a certain limit. That didn’t seem to work as interrupt() sets a flag (which can be retrieved through the interrupted() method) if the target thread is not executing one of sleep(), wait() or join(). This did not help. As another solution, Colin found a reference in Sun’s Java Developer Connection to a system property called http.defaultSocketTimeout which would set the timeouts on HTTP connections. This did not work either, for the simple reason that they renamed the property to net.client.defaultSocketTimeout and then to sun.net.client.defaultReadTimeout and sun.net.client.defaultConnectTimeout in J2SDK 1.4.1. Using the former of those last two properties successfully set the read timeout (that being the maximum time allowed between reading one byte and then reading the next) for all connections. Of course, we would not have found this out if Colin hadn’t seen this bug (NOTE: viewing JDC bugs requires a login), which contains a link at the very bottom to the Java networking properties.

The above information is useless if you are stuck with a JVM which doesn’t support 1.4. You will have to somehow close() the underlying connection, probably from a thread which directly monitors that connection. You could also write your own streams.

Naturally, setting a property which affects all connections in your application is a bad idea, but Java doesn’t provide you with any other way unless you have access to the underlying socket, at which point you could use Socket.setSoTimeout(). There is a bug requesting the addition of non-global timeout properties for HTTP connections, but this won’t be fixed until Tiger AKA Java 1.5.

People, Java has only been around for some seven years and we’re only just getting per-connection read timeouts? Why wasn’t this done sooner? Is nobody actually using Java as it was meant to be used? Isn’t Java supposed to be a network programming language? It’s not like people don’t want this feature. I mean, look at this bug which requests the ability to set socket options on a URLConnection. That bug has been around since early 1998, has had 217 votes placed on it and is still labelled as “In progress, request for enhancement”!

Java, baby, I loves you but why you gone make me hurt you so?

Posted on December 12th, 2002 in computers, java, programming - No Comments »