alan little's weblog

python and java (and perl)

26th July 2003 permanent link

Russell Beattie has written a couple of articles recently on python from a java programmer's perspective. I haven't put as much time and effort into trying out python as Russell has - in fact, I gave up and went back to java pretty quickly, because that way I could be productive instead of spending hours and days banging my head against the kind of frustrations Russell has written about.

My previous consulting gig finished at the end of June, and with all the time I suddenly had available (in an apartment with a six week old baby - ha!) I decided to get moving with a couple of programming projects I've wanted to do for a while - an analyser for my web server logs, and a weblog tool. (Yes, I know there are dozens of both readily available, many of which are free and open source, but that's not the point ...). I've been thinking for some time that it would be nice to learn python, and one or both of these seemed like an ideal easy-but-interesting starter project. On the other hand, I hadn't used java for a while and from a looking-for-employment point of view I thought it might not be a bad idea to brush that up a bit. Nevertheless, I decided to start with python - which I had already played with a bit using Mark Pilgrim's excellent Dive Into Python - on the basis that it's a nicer language. I still think it is, but read on ...

First I needed to get my development environment set up with various tools that I knew I was going to need. I'm used to perl, where tools to help with anything you could possibly want to do are available on cpan and you just download them - or, if you're on Windows, you just fire up activestate's excellent module installer and it does everything for you. Or java, where most of what you want is in the standard libaries and if you do need something third party, such as the excellent JFreeChart, you just put a couple of .jar files in the right place, read the javadoc and away you go.

With python, it doesn't seem to be like that. I wanted to hook python up to MySQL. There doesn't seem to be anything to do that in the standard modules that are available on python.org. So I did a search on google and got pointed to the home page of the guy who wrote something called mysqldb, but when I went there it said the current version had moved to sourceforge. I downloaded it from sourceforge. It didn't build. Firstly because, oops, no gcc. I had forgotten I had installed the Apple developer tools on the laptop, but now I was on the desktop which had previously spent its working life as a photoshop workstation. I downloaded the latest developer tools. Fair enough, if I need a C compiler then I need a C compiler - but I've never had to bugger about with C compilers to install a simple perl or java library to do something as fundamental as talking to a database. The MySQL thingie still wouldn't build. I googled the error message (something bizarre from gcc about being asked to build i386 code and not wanting to, which I suppose is within its rights if it knows it's running on a Mac), and found somebody who said he had submitted the fixes to setup.py for OS X to the developer months ago (but they're still not in the supposedly latest version that I had just got from sourceforge). I made the fixes. It built, but still didn't actually work when I fired up python and tried to use it.

I googled some more, and found a link to another page suggesting some different fixes to get setup.py to work properly on OS X. The page wasn't there any more. I grabbed it from the google cache. Haven't tried it yet though, the whole experience so far has just been too depressing and discouraging and meanwhile I've been busy actually getting work done in java.

I know it's always frustrating getting to know a new development environment - I've learned enough over the years to know I should budget at least a full day mucking about with stupid configuration settings before I can actually get anything productive done. But the impression I'm getting so far is that python the environment is like perl the language - powerful but messy, inconsistent and a certain amount of aggravation and trial & error required. (Whereas perl the environment is like python the language - things are generally clean, elegant and it Just Works)

Meanwhile I already have a working version of the log analyser and have made a start on the weblogging tool (which isn't generating this page yet but will be in a day or so, baby permitting) using java, which is frustratingly verbose and irritatingly pedantic with its type and exception checking, but also Works.

related entries: Programming

all text and images © 2003–2008