Monday, February 07, 2005

Nice things about Java

After my previous moans about Java, it's probably only fair that I say something nice about it. If you've been following our story so far, I have a Java stored procedure in an Oracle database, which calls Runtime.exec to fire off a Python program which generates some results for me.

The programs communicate via stdout, using a home-brew text format (I gave up on XML) - it's not very complex, but a surprising amount of the Java code is dedicated to parsing it. Then it occurred to me that I could use Java's serialization features to pass data round - if the external program was in Java. A quick test later, and it surprised me - it just works. And no problems pushing serialized data through stdout either (this is on Windows, where text mode is a permanent thorn in my side).

That was surprisingly neat. The code is still a bit verbose to my mind for what it does, but it all interoperates just like that. Yes, I know Python could do the same via pickle, and I know I can't fault Python for not being able to write Java serialized objects any more than I can fault Java for not being able to read Python pickles, but that's not the point. It's a language vs library thing again - Java's libraries are very rich, like Python's. The style differs radically but I'd rather dislike the style than lack the functionality.

And some things just aren't as neat in Python. Passing binary data via stdout is dodgy in Python because of text-mode issues. I couldn't see how Java dealt with text mode at first, until I realised that was what the Reader/Writer interfaces were for. At the bottom level, all IO in Java is binary, and you have to wrap a codec round a stream to get character IO. Python can't be that "pure" because of the historical use of strings as byte buffers. Whether Python could become stricter, I don't know. And whether it could do so while still remaining "Pythonic", I'm even less sure.

But it's nice, for a change, to be able to sling data round without enduring "fear of text mode" all the time.

So, I'm getting more tolerant of Java. Not a fan, not even a convert, but at least not as biased against it. After all, we're all consenting Von Neumann machines when it comes down to it...


Post a Comment

<< Home