April 30, 2004
I'm gonna get medieval on your ass

Weather permitting, I'll take the girls to the medieval fair on Sunday. Should be nice.

Posted to Music and Film by Simon Brunning at 11:46 AM
April 29, 2004
Misogynist? Me?

I've got nothing on this guy.

Me, I'm well aware of the fact that the problem is on my side. It's not that all women are bitches, it's just that all the women I fancy are bitches.

Sadly, this self awareness doesn't really help. I've got the hang of avoiding the psycho-witches-from-hell, but you can't make yourself fancy poeple just 'cos you think you ought to.

Not that I actually meet any women these days. Working in IT for a company specialising in Insurance software, and having no trace of a personal life, I might as well be a monk. :-(

Well, enough of this whinging; I'm off to the pub. Beer good.

Posted to Apropos of nothing by Simon Brunning at 04:32 PM
The power of RPG

RPG's built in %DEC function is generally happy with embedded spaces - but if the string that you are trying to convert is completly blank, it throws an error. This is fair enough, I suppose, but not what I want - I want a zero.

No problem, thought I. I'll throw together a quick subprocedure.

 **********************************************************************************************
 * Convert string to packed decimal                                        
 **********************************************************************************************
p str_to_packed   b                                                                            
d str_to_packed   pi            31p11                                                          
d  from_str                     40    value                                                    
d  precision                     2p 0 value                                                    
d  scale                         2p 0 value                                                    
                                                                                               
d return_value    s             31p11                                                          
                                                                                               
c                   if        from_str = *blanks                                               
c                   eval      return_value = *zero                                             
c                   else                                                                       
c                   eval      return_value = %dec(from_str:precision:scale)                    
c                   endif                                                                      
                                                                                               
c                   return    return_value                                                     
                                                                                               
p                 e                                                                            
 ********************************************************************************************* 

Does this work? Does it fuck. It fails to compile, because the %DEC function needs its scale and precision arguments fixed at compile time, would you believe. Arse.

Update: Looks like I'll have to do it the hard way. Sigh.

And while I'm ranting about RPG, what's the bloody point of introducing exception catching if you can't raise exceptions?

Posted to iSeries by Simon Brunning at 02:39 PM
Don't Return References to Mutable Objects

Don't Return References to Mutable Objects, says Adam Kolawa.

Absolutely right - but for the wrong reason, I think. The security concerns he cites are not the real problem - as Ted Neward points out, if somebody's running code in your VM, you are already dead. No, the problem with returning references to mutable objects is that it's a pistol. It's all to easy for someone else to hose your object by accident. What's more, if this happens, it's a really hard problem to diagnose. You can look at your classes code all day, and put as many breakpoints in there as you want to, and you'll never see where it goes wrong.

Trust me, I know. ;-)

See also Joshua Bloch's Effective Java (which I can't recommend too highly) and Java Practices: Immutable objects.

This is as pertinant to Python as it is to Java, BTW, as is much of Effective Java.

Posted to Java by Simon Brunning at 01:07 PM
Nice box

Mark hasn't even started at his new job yet, but already he's spending his ill gotten burger flipping wages; he was showing off his new GeForce FX 5900 XT last night.

Not that it looked that impressive - a box is a box, after all. You have to plug the thing in before it's impresive.

So, Mark, how was it for you?

Posted to Toys and games by Simon Brunning at 12:41 PM
Halfway There

Last night was a good one; Steve, Andy, Michael and Mark all made it, much beer was drunk, and many World issues were resolved.

(We've decided that we don't want ID cards, so you can just stop now, Mr Blunkett sir.)

So, anyway, I'm now hoping that I recover from my hangover in time to give myself another one.

Posted to Apropos of nothing by Simon Brunning at 11:04 AM
I Like It Like That

You know that catchy Salsa style Odeon theme? Google to the rescue! It's by one Pedro Rodriguez, and it's called I Like It Like That.

Posted to Music and Film by Simon Brunning at 10:57 AM
April 28, 2004
Ditch the victim mentality

A brilliant opinion piece in The Register: Ditch the victim mentality.

Users want "effective, free, constantly updated security service requiring little or no user intervention". "It is fantasy", says Tim Mullen, "nothing like that will ever exist, as it simply cannot. New threats emerge every day with new associated risks, and there will never be any unified solution to the sea of possible attacks."

The user must take some responsibility, he says: "You don't have to be a computer expert to load AV software and install a firewall. We are not wasting energy blaming stupid users. We are calling for users to take a little time and to learn minimal skills before attaching their systems to the Internet. The time it takes for these innocents to wallow in victimization would be far better spent actually reading all those message boxes telling you that you are about to screw up your system before clicking OK."

To which I'd add: And no more opening bloody email attachments!

Posted to Software by Simon Brunning at 04:19 PM
PyCon DC 2004

Mike Orr has written a nice report: PyCon DC 2004. He covers many talks in detail.

Which reminds me; I must get around to looking at Twisted at some point. Well, I've recently picked up Game Programming With Python, and it's covered there...

More Python related stuff: Alex Martelli's Tightening Python's Grip in Enterprise and How Python Tightens Its Enterprise Grip offer a good introduction to Python for Win32, Java and .NET developers.

Posted to Python by Simon Brunning at 01:15 PM
April 27, 2004
More desktop toys

Via The 46 Best-ever Freeware Utilities, via Rikei, I've found some new toys: Hotkeycontrol XP, TinyResMeter and Startup Control Panel. And via Gordon McLean, even more: Samurize!

All very silly.

Posted to Software by Simon Brunning at 02:23 PM
Windows shutdown

Anyone know how to get things to run as I shut Windows down?

I'm running XP Home. Yes, yes, I know. :-(

Running stuff on startup, no problem. On closedown, I've no idea.

Posted to Software by Simon Brunning at 02:01 PM
Going out two nights on the trot!

Crikey, what a dirty stop-out! Anyway, it's Mark "the burger-flipper" Matthews' leaving do on Thursday night this week, at the All Bar One, Houndsditch.

Wednesday night is looking promising; Steve's coming, of course, and Andy, Michael, Mark and Sam are all probables. The more the merrier, of course, so do come for a beer if you're London based and at a loose end.

Be gentle with me on Friday morning...

Posted to Beer by Simon Brunning at 01:55 PM
Winspector

Another one for the you-don't-need-this-but-if-you-need-it-you-need-it-bad department: Winspector.

If you need to look at your Windows desktop from underneath, seeing all the gruesome details of all the windows, dialogs and controls, and all the messages being sent around, this is for you. If you don't have access to Microsoft's Spy++, or even if you do, it's worth a look. Useful, for example, when using winGuiAuto.

Posted to Software by Simon Brunning at 01:35 PM
April 26, 2004
Quote of the day

Why Python is better than Java: What it comes down to is not just that Java places too high a cognitive load on the programmer... it's that Java's just a pain in the ass.

You try RPG, mate. ;-)

Posted to Funny by Simon Brunning at 04:23 PM
April 23, 2004
Anyone for a pint?

I'll be meeting Steve at The Stage Door on Wednesday evening. Beer drunk, girls ogled, World issues resolved. All welcome.

Posted to Beer by Simon Brunning at 04:24 PM
UK Open Source trade association

Open Sourcerers get UK trade body. "The association will promote open source in general, and Zope, Plone and Python technolgies in particular." Cool! Good job, Andy and Seb.

Visit the association at Zope UK.

Posted to Open source by Simon Brunning at 03:17 PM
Python for Nokia Series 60

Looks like it's really happening: Amaretto: Nokia's Python for Series 60.

Update: There's a nice write up on this in the Grauniad: Ben Hammersley's Let's get personal.

If this becomes generally available, it'll mean the end of cheapo pay-as-you-go phones for me.

Posted to Python by Simon Brunning at 03:02 PM
jvmstat

There are never performance issues with any of my systems, so I'm not remotely interested in jvmstat. Honest. ;-)

Posted to Java by Simon Brunning at 12:49 PM
Man of Steel

So, David 'Man of Steel' Blunkett is taking terrorist suspects and turning them psychotic. Great. I feel much safer, don't you?

It's impossible to tell how many of these "terrorist suspects" are really dangerous before their incarceration without trial, and how often it's just paranoia.

Posted to The Big Room by Simon Brunning at 10:26 AM
April 22, 2004
Nooooobody expects the Spammer's Imposition!

Nooooobody expects the Spammer's Imposition!

Via qwghlmBlog.

Posted to Funny by Simon Brunning at 04:47 PM
XFM

God, I hate XFM.

The problem isn't the music. The music isn't too bad at all, though the playlist is a little short, so it gets a bit repetitive.

No, the problem is all the bloody talking. The 'zany banter' between the records is bad enough, but the ads are driving me insane.

Funny thing is, I love Radio 4. So perhaps it isn't talking that I object to so much as asinine bollocks.

Posted to Music and Film by Simon Brunning at 03:18 PM
What do women need us for?

As things stand, there are very few things that women really need men for these days; they need us to have children, they need us to blame for everything, and they need us to remove spiders from the bath. That's it, I think.

Now there's the prospect that they won't need us for the first of these in the future - two mothers, no father. So, let's hope that science doesn't come up with replacements for us on the other two fronts, eh?

Posted to Science and technology by Simon Brunning at 02:19 PM
Signifying nothing

The Shakespeare Programming Language, via Squawks of the Parrot.

Not quite as nerdy as Var'aq (the Klingon programming language), but every bit as silly. Fantastic!

(Prime gereration in Shakespeare.)

Posted to Funny by Simon Brunning at 01:06 PM
Getting started with Hibernate and Spring

I've been meaning to look into Hibernate and Spring - they seem to be the Java tools de jour, and I'm assured by some clever people that they are very good. I've just read Object-relation mapping without the container, Develop a transactional persistence layer using Hibernate and Spring, and I think I'm beginning to see the light. Certainly looks a good deal less hastle than coding your own DAOs!

I'm still a bit worried about using LGPL software in the context of a commercial Java application, though...

Posted to Java by Simon Brunning at 12:59 PM
April 21, 2004
Thelonious

I've put some Thelonious Monk on. It's not going down too well. :-(

"Thelonious Sphere Monk" - that's a name! I suppose that he didn't have too much choice of career with a name like that; it was either jazz-man or preacher.

I might try Bluesbreakers next.

Oh, and thanks foir pointing out http://www.allmusic.com, Sam. It's a great site.

Posted to Music and Film by Simon Brunning at 01:48 PM
Command line parsing

I mentioned Michele Simionato's lovely command line parser the other day. The nice thing about this is that it takes the command line option definitions from a human readable definition in the module's docstring.

David Boddie commented on this recipe, pointing out his lovely command line parser. The nice thing about this one is that it can throw up an automatically generated GUI form allowing the options to be specified in addition to accepting the options from the command line. (There's nothing new in the world - this is similar in concept to the way the iSeries' commands work.) But the syntax that David's parser uses isn't too user friendly.

So, what I'd really like would be a combination of the two approaches; David's GUI generating parser, but driven from a human readable docstring. Well, I have the code to both, so I'll have a bash at a cut-n-shunt job.

Posted to Python by Simon Brunning at 01:18 PM
End of Jython hiatus

Things are happening in Jython land again. Firstly, there's a new alpha release. It's not ready for the real world yet, it's true, but it's nice to see concrete progress.

Also, there have been a number of Jython related articles and blog postings recently; The Way You Develop Web Applications May Be Wrong, Fun with Jython, Introduction to Jython, Part 1: Java programming made easier and Part 2: Programming essentials, and Simplify Web development with Jython, Spring and Velocity.

Which brings me on to Spring. I'm always a bit suspicious when something looks too good to be true, (after all, why settle for snake-oil then you can have the whole snake,) but Sam assures me that Spring really is as good as it claims to be, so I'm tempted to give it a bash.

Update: A couple more good recent Jython articles: Use Jython to Write Ant Tasks and Learn how to write DB2 JDBC tools in Jython.

Posted to Python by Simon Brunning at 12:32 PM
Where to put Python

Rand Anderson seems to regret installing Python to c:\dev\python23 on his Windows box. Hmmm, that's exactly the same place that I install it to, and it's never given me a moment's trouble. I wonder what is giving him problems?

Posted to Python by Simon Brunning at 12:12 PM
Without the aid of a safety net

Bugger! Bloody SEU doesn't have an undo facility. I just deleted a whole bunch of source by accident. :-(

That's two hours work down the drain...

Posted to iSeries by Simon Brunning at 12:09 PM
April 19, 2004
Python recipes

There have been a couple of very interesting Python recipes added to the Python Cookbook recently.

I love Michele Simionato's Parsing the command line. Parsing the module's docstring for the command line options is a brilliant idea. It feels really pythonic; most other languages, for example, treat indentation as purely documentary, and require you to repeat your code block delimitation using delimitation characters and using indentation, whereas Python treats the indentation as definitive, and doesn't require you to repeat yourself - DRY! Similarly, this recipe treats the docstring's definition of the supported command line options as definitive, and doesn't require you to repeat yourself.

Raymond Hettinger's Bind Globals into Constants at compile time is a lovely example of the kind of thing that Python 2.4's method decorators are designed to support.

I have to say, I'm not that keen on the current decorator syntax; a list of decorators on the line preceding the function/method definition looks ugly to me. I'd prefer the decorators in the def statement somewhere, or inside the function somewhere, like the docstring. But what do I know; Guido's the world-class language designer, after all!

Posted to Python by Simon Brunning at 12:43 PM
How was Python UK 2004?

How was Python UK 2004? Python Programmer Weblogs, python-uk and c.l.py are all silent on it...

Posted to Python by Simon Brunning at 10:52 AM
April 16, 2004
A touch of class

My turn to put a bit of music on at the office; Time Out and The Jimmy Giuffre 3.

Ahhhh!

Posted to Music and Film by Simon Brunning at 04:18 PM
Epydoc

Somehow, I've not come across Epydoc before. I'll have to give it a bash: look what a lovley job it makes of the standard library!

Posted to Python by Simon Brunning at 02:35 PM
Converting Word documents to text

The thing I love about Python is that if it sounds simple, it usually is. Here's a script to save all Word documents in and below a given directory to text:

import fnmatch, os, pythoncom, sys, win32com.client

wordapp = win32com.client.gencache.EnsureDispatch("Word.Application")

try:
    for path, dirs, files in os.walk(sys.argv[1]):
        for doc in [os.path.abspath(os.path.join(path, filename)) for filename in files if fnmatch.fnmatch(filename, '*.doc')]:
            print "processing %s" % doc
            wordapp.Documents.Open(doc)
            docastxt = doc.rstrip('doc') + 'txt'
            wordapp.ActiveDocument.SaveAs(docastxt, FileFormat=win32com.client.constants.wdFormatTextLineBreaks)
            wordapp.ActiveWindow.Close()
finally:
    wordapp.Quit()

Requires Python and the Python for Windows extensions.

My stepmother has been horribly virus hit, so I'm off to rebuild her PC this weekend. Sigh. I'll burn a CD with all her data before the rebuild, of course, but I'm worried that some or all of her documents might be infected - so I'll back them all up as text files, too, so that in the last resort, she'll still have all her work.

Update: As Ryan points out, it also requires a copy of Word. Thanks, Ryan: I should have mentioned that.

Another update: I cleaned this up a little and submitted it as a Python Cookbook recipe: Converting Word documents to text.

BTW, the rebuild was a nightmare. Win2K refused to recognise the modem, which is, of course, the worst thing that could possibly have happened. I ended up buying a new one. The whole job, including running Windows Update etc, ended up taking over nine hours!

Posted to Python by Simon Brunning at 02:32 PM
April 15, 2004
Python UK conference tomorrow

Good luck to all the organisers and attendees at the UK Python Conference 2004, which starts tomorrow. Have fun, ladies and gentleman. I wish I could be there with you...

Posted to Python by Simon Brunning at 01:02 PM
April 14, 2004
London Java Meetup - 19 Apr 2004

It's Nerd Pride night once again - London Java Meetup - 19 Apr 2004. London based Java nerds shouldn't miss this. Thoroghly bloody nice bunch of chaps.

(Yes, all chaps. Funny that...)

Posted to Java by Simon Brunning at 01:42 PM
Using Digester and BeanUtils

Back in the old days when I was a Java developer (sigh), I made extensive use of several Jakarta Commons packages. Lang and Math are pretty much self explanatory, but I found the BeanUtils and particularly Digester a bit harder to get into. Jason Menard has put together a couple of very nice introductory articles: Touring the Commons - part 1 (discussing BeanUtils) and part 2 (discussing Digester). I wish I'd had these when I was learning my way around these packages!

If you aren't using these packages, take a look. They are all really useful.

The other package that I had to fight my way into was Collections. Any nice tutorials out there for this?

Posted to Java by Simon Brunning at 01:26 PM
Jenny - The Database Code Generator

Back when I was looking at building some Java DAOs, I had a good look around for something which would build them for me. I never found Jenny, which is a pity, because it looks like almost exactly the sort of thing that I was looking for.

Via Gregg Bolinger.

Posted to Java by Simon Brunning at 01:10 PM
April 13, 2004
Grammar joke of the day

Two busty coeds—a Southern belle and a New England yankee—are in Florida on spring break. The belle turns to the yankee and asks, "So, where y'all from?"

The yankee turns up her nose and says, "I'm from a school where we don't end sentences with prepositions."

Without missing a beat, the belle replies, "So, where y'all from, bitch?"

Courtesy of Mark Pilgrim.

Posted to Funny by Simon Brunning at 05:27 PM
WinGuiAuto.java

Brian Edwards has put together Java port of winGuiAuto.py. Little does he know that I've been cleaning this up over the last week or so, a version 1.0 release is just days away, and he'll have to do it all over again. Mwahahahahaha!

Seriously, Brian, cool stuff. BTW, you use Coroutine for Java, and say that you are looking for an open source alternative. Well, I gather that there's a Java port of Thomas Heller's fabulous ctypes module in the works: ctypes-java. You might want to take a look.

Also, did you do any of the Python to Java conversion automatically? (It certainly looks like it.) What did you use?

Posted to Java by Simon Brunning at 05:10 PM
A language comparison: postcode splitting in RPG and Python

As you might have guessed from my last post, I've got some postcode parsing to do. The requirement is pretty simple; I have to parse a postcode into an outcode and (optional) incode. The good new is that I don't have to perform any validation - I just have to chop up what I've been provided with in a vaguely intelligent manner. I can't assume much about my import in terms of formatting, i.e. case and embedded spaces. But this isn't the bad news; the bad news is that I have to do it all in RPG. :-(

Nevertheless, I threw a little Python function together to clarify my thinking. I often do this when I'm coding something nasty in Java. It's worthwhile to make sure that the algorithm that I'm using works before grappling with Java, and Python is perfect for this. And given RPG's awkwardness, it's worth prototyping even the simplest algorithm - you don't want to spend all that time cutting code only to find that it doesn't work even in principal!

Anyway, the Python function:

def parse_uk_postcode(postcode):
    postcode = postcode.replace(' ', '').upper()
    if len(postcode) <= 4:
        return postcode, ''
    else:
        return postcode[:-3], postcode[-3:]

(A syntax highlighted version with unit tests here: postcode.py.)

Then I put the RPG version together: postcode.rpg. It's much longer and ugler, but it seems to work.

This is a very tolerant way of dealing with postcodes. It will accept just about anything. In my case, that's what I want; I'm pulling data in from a big SAP database. If that's inaccurate, it's definitively inaccurate. ;-)

In other cases, you might want to validate the postcode. Even here, you have more than one choice. One approach is to make sure that the postcode follows the rules as specified at the Universal Postal Union and the UK Govornment Data Standards Catalogue. I've coded this up: postcode_strict.py. This might even be useful to someone! (I didn't bother with an RPG version of this; I don't need one, and life's too short for writing this kind of thing in RPG if you don't really need it.) The other approach would be to validate against a list, should you have one. Duncan Gough steered me towards Brainstorm's downlaodable postcode lists, but these contain outcodes only.

Oh, BTW, any suggested improvements to any of these functions in any of these languages would be gratefully recieved, as would Java versions for comparison.

Update 14th April: Alan Green's done a Java version of the simple version. Thanks, Alan!

Also, I've spotted a bug in the strict version, which I'll fix at lunchtime. Basically, I'm using the list of characters valid at the 4th position to check characters at both the 3rd and 4th positions. This is incorrect; there's a different list of valid characters for the 3rd position. :-(

Another update 14th April: It's fixed, it works now, and I've even added a docstring or two. Look at postcode.py, or download a zip file containing postcode.py.

Posted to iSeries by Simon Brunning at 04:57 PM
April 07, 2004
Postcode formatting

OK, sorry about this. Remarkably tedious (if rather useful) post coming up.

Everything you will ever need to know about UK address and postcode formats (in PDF), via the Universal Postal Union (where you can find similar documents for other countries' address formats), found via forta.com.

Posted to Software development by Simon Brunning at 04:10 PM
Science triumphs over common sense once again

Kangaroo genes could boost milk. Insert your own milk-shake joke here.

It's only a shame that this story wasn't released last Thursday, really.

Posted to Science and technology by Simon Brunning at 10:49 AM
April 05, 2004
Bye, Mark

Mark 'the burger-flipper' Matthews just called to tell me that he's got another job. This is terrible! Who am I going to bait about VB and Hungarian notation now?

All the best, mate, and don't forget to tell me when the leaving do is...

Seriously, Mark and I do argue a lot, but it's from a position of mutual respect, and it's productive arguing. His technical skills are good, as are his design instincts, and he's a good trainer. He's a real asset to the team, and a bloody nice chap to boot, so he'll be missed.

Just don't tell him I said so. ;-)

Posted to Beer by Simon Brunning at 02:57 PM
Eckel on typing Java and Python

Bruce Eckel (of Thinking in Java fame) has been posting recently on his increasing disillusionment with Java's typing scheme, and how's he's finding that what he calls "Latent" typing is better, in practice if not in theory. (Eckel's "Latent" typing is what a Pythoneer would probably call "Dynamic" typing and a Ruby-head "Duck" typing.) The whole set of posts are worth a read: Generics Aren't, About Latent Typing, How to Argue about Typing and I'm Over It.

Posted to Python by Simon Brunning at 02:10 PM
What's wrong with RPG

It's been quite a while since I've been an RPG programmer. Now I'm back with it for a month or two, and I can't say that I'm liking it much. I've become accustomed to loads of nice things that I no longer have available.

Firstly, there's the language itself. RPG is ugly, inexpressive and fiddly. I think that these are somewhat related - to quote ESR, Ugly programs are like ugly suspension bridges: they're much more liable to collapse than pretty ones, because the way humans (especially engineer-humans) perceive beauty is intimately related to our ability to process and understand complexity. A language that makes it hard to write elegant code makes it hard to write good code.

A few examples: Opening a file in anything but the most standard of ways involves fiddling with an unholy mix of F, D and I specs, all of which are column oriented records, and all of which need to be located in different parts of the source deck. The C specs don't have to be column oriented, but I've yet to see the new free format RPG used in anger. Using the old style column oriented C specs, if your expression gets too long, it'll end up running into the comment column, and will be ignored. If you're unlucky, the compiler won't notice, and your expression will compile with a bit missing. This gets picked up in testing, of course, but there ain't no jUnit for RPG.

There's a narrow range of activities for which RPG works reasonably well, and it must be said, it's very well integrated with the iSeries's built in database. The iSeries is pretty much an accountant's machine, and you can build the applications that you want with RPG, I suppose. But all the fiddling leaves you with appalling productivity.

Then there's the standard library. Or, to be more specific, the complete and utter lack of one. Java has a huge standard library, and Python's standard library is either even larger or much smaller, depending upon whether you are talking about functionality, or lines of code. ;-) And if I can't find what I'm looking for in the standard libraries, well, Google and PyPI are my friends, and there's almost always something to download. RPG, on the other hand, has no standard library at all, and there's little stuff on the 'net. RPG does support software components, just about, but there isn't a community making stuff available. So, every project reinvents its string and date handling, for example.

Lastly, there's the development environment. The site that I'm at, just like every other iSeries site that I'm aware of, use the SEU source editor, which is out of the Ark. This is particularly irritating, because there's a fantastic Eclipse-based replacement, WDSc. This comes as part of the same WDS bundle as SEU does, so if you have one, you have the other - but no one uses it!

In short, if you catch me whinging about Java again, just slap me.

Posted to iSeries by Simon Brunning at 01:54 PM