Java XML support...

darobin on 2002-12-05T15:24:01

...sucks. And today I got tired of it so I (partially) ported XML::SAX::Machines::Pipeline and XML::Filter::BufferText to Java. Boy, life's hard when you don't have AUTOLOAD. Here's a sample from the new fr.expway.sax.filters.BufferText:

    public void startElement (String ns, String ln, String qn, Attributes attrs) throws SAXException {
        sendChars();
        getContentHandler().startElement(ns, ln, qn, attrs);
    }

    public void endElement (String ns, String ln, String qn) throws SAXException {
        sendChars();
        getContentHandler().endElement(ns, ln, qn);
    }

    public void processingInstruction (String tgt, String data) throws SAXException {
        sendChars();
        getContentHandler().processingInstruction(tgt, data);
    }
...

And it just goes on and on... talk about the DRY Principle in action. Compare that with the original. Java is generally anti-DRY, with constructors having the name of the class and other stupidities like Foo foo = new Foo() but I rarely felt it this strongly.

Similarly, in order to make Pipelines work naturally (whereby you can pass in objects or class names), I had to defeat the type system with lovely constructors like new Pipeline(new Object[]{foo, "myClass"?, ...}) and generally do casts from Object into something else the type of which I just tested all over the place, in static arrays.

I am deliberately not releasing this as Open Source. If anyone uses this language for reasons other than commercial, they deserve the pain.


Ugh.

ziggy on 2002-12-05T19:15:22

It's been a while since I looked at Java code. How can you tell what this snippet of code does? There are just too damned many words to parse! How are you supposed to see what it's doing just by looking at it?

If you need to be using Java, can't you use something like a JScheme, Jython or JRuby to run code within the JVM?

Re:Ugh.

rafael on 2002-12-05T20:32:55

I think that Java is a great language for educative purposes, because its verbosity forces you to think about what you're writing, and because it's simple enough to be understood by beginners. However, for serious stuff, I'd use Perl. And before going serious, I'd force people to learn C, because understanding pointers is important. Java seriously lacks multiple inheritance (not speaking about double dispatch) and its core classes (String, Class) are flawed by implementation details and performance considerations (they're final in Java terms, in other words they can't be subclassed.) This prevents almost all forms of elegant and concise design. Especially the forms of design that appear in the brain of anybody who is familiar with the Damian's perl modules ;-

Re:Ugh.

darobin on 2002-12-06T09:57:28

If you need to be using Java, can't you use something like a JScheme, Jython or JRuby to run code within the JVM?

I wish, but unfortunately the reason I'm using Java is because I'm doing research stuff, and Java is pretty much the lingua franca. A lot of people think it has serious flaws, but it's the only thing you can use that you're sure all others will understand.

I guess we better get up to speed with those taking over of the world with Perl6/Parrot ideas ;)