February 27, 2004
What One Hand Giveth...

What One Hand Giveth, the Other Taketh Away.

Ah well. As a single man, it's all pretty academic to me anyway. Just as it is for married men, so I gather. ;-)

Posted to Science and technology by Simon Brunning at 02:21 PM
Code Complete

Steve McConnell's Code Complete is one of the best books on software construction ever written, IMNSHO. Every standards manual (or as I prefer to call them, coding style guide) I've participated in since I came across Code Complete has been based upon it.

So it's great to hear that there's going to be a second edition. This new edition covers the construction of OO software, which the first edition did not. The draft is on line - looks good.

Via paradox1x.

Posted to Software development by Simon Brunning at 02:11 PM
DAO testing

A good indication of when you are really starting to get to grips with a subject, I find, is when you start to know the right questions to ask. (Knowing the answers to these questions comes much later. That's expertise.) Once you are at this point, you can really start to take off: if only because once at this point, Google can usually help you out.

Well, when it comes to JNDI, I'm nowhere near this point. I'm out of my depth here, and I know it.

I'm putting together the unit tests for my DAOs. (Yes, yes, I know I should have written the tests before writing the DAOs themselves. Let's face it; I'm a bloody amateur.) The DAOs get their connections from a pool, like so. This clearly isn't going to work in my unit tests unless I sort out the context stuff beforehand - and I haven't a clue how to do this. Putting together a harness DataSource is trivial. It's the InitialContext and Context stuff that I don't understand.

I came across Using mock naming contexts for testing by Simon Brown, which looks like it ought to get me going - but my brain just isn't making the leap. Sigh.

(Simon's a lovely chap, BTW. I've met him a couple of times at the London Java Meetups.)

Posted to Java by Simon Brunning at 01:47 PM
February 26, 2004
Impromptu London Python Meetup

There's an impromptu London Python meetup this evening at The Chandos, near Trafalgar Square. I had already arranged to meet Steve for a beer, so we changed venue; I'll be there.

Posted to Python by Simon Brunning at 10:13 AM
February 24, 2004
Imaginary Girlfriend

So, if I'm not allowed a real girlfriend, am I allowed an imaginary one instead?

Via Off on a Tangent.

Posted to Funny by Simon Brunning at 01:17 PM
Locating the configuration files for my J2EE app

Arrrrrgh! I just can't believe that this is hard! (Or perhaps it's just me that finds this hard. That's not so difficult to believe.)

OK, so, the J2EE application we are working on needs some configuration, so I've monkied up a quick Digester based configuration file reader. That should have been the hard bit, but it's been a piece of cake. Digester is great!

But now I need to get it to read the configuration file from within my J2EE application. So where do I put this file, and how do I tell Tomcat (or whatever) where to look for it?

I've currently got this file in WEB-INF/config.xml, which feels right. But Tomcat can't find it given just this as a file path. I suppose that I need to prepend the document root to this - but how do I find that? (I'm currently trying to read this file in a ServletContextListener's contextInitialized method.)

Naturally, I'd rather not use anything Tomcat specific if I can help it. But I did try this:

final ProxyDirContext proxyDirContext = (ProxyDirContext) servletContext.getAttribute("org.apache.catalina.resources");
final String docBase = proxyDirContext.getDocBase();

But unluckily (or perhaps luckily) this didn't work. It *would* work from a Servlet, I think, but the org.apache.catalina.resources context attribute doesn't seem to exist as the context is initialised.

Arrrrrgh!

Posted to Java by Simon Brunning at 12:49 PM
February 23, 2004
Get it while it's hot!

Get it while it's hot!

Via GromBlog.

Posted to Funny by Simon Brunning at 01:33 PM
My blog stinks

Well, I like to think it doesn't, but one day it might...

OK, OK, perhaps it does. :-(

If your blog had a smell, what would it smell of?

Posted to The Internet by Simon Brunning at 10:57 AM
MMR in the news again

The MMR danger myth - it just won't die. And this despite what the science is clearly telling us. Not only was the Wakefield study flawed, but now it seems that Dr Wakefield had a vested interest in stirring it up.

It's becoming rather difficult not to see Andrew Wakefield as a villain in this. To begin with, I thought that he was just wrong - well intentioned, but wrong. But now it looks as though there was more to it that that... If there is a measles epidemic in this country, there will be blood on his hands.

Update: Oh no - no one will believe it's safe now. :-(

Posted to Science and technology by Simon Brunning at 10:38 AM
February 20, 2004
Romance is truly dead

And about bloody time, too.

My theory is that there is now a man in Ken's life. I mean. look at him - have you ever seen anyone more immaculately groomed?

Via Aderemi.

Posted to Funny by Simon Brunning at 04:10 PM
Staying on focus

We seem to have trouble with this. We just spend some time in a meeting discussing whether a certain white-board pen was green or blue.

It was blue, goddamn it!

Posted to Apropos of nothing by Simon Brunning at 03:45 PM
February 19, 2004
DAO coding

I've spend some time recently putting together the DAOs for my project. Quite some time, in fact. God, they are ugly.

The Transfer Objects, the ones that ones that you end up using outside the persistence layer, seem usually to be coded as beans. So, the class which builds these objects has to set a bunch of properties:

principal.setPrincipalName(result.getString("PrincipalName"));
principal.setAddress1(result.getString("PrincipalAddress1"));
principal.setAddress2(result.getString("PrincipalAddress2"));
principal.setAddress3(result.getString("PrincipalAddress3"));
principal.setAddress4(result.getString("PrincipalAddress4"));
principal.setAddress5(result.getString("PrincipalAddress5"));
principal.setPostCode(result.getString("PostCode"));
principal.setContactName(result.getString("ContactName"));
principal.setContactPosition(result.getString("ContactPosition"));
principal.setTelephoneNo(result.getString("TelephoneNo"));
principal.setFax(result.getString("Fax"));
principal.setEmail(result.getString("Email"));
principal.setPredominantCurrency( result.getString("PredominantCurrency"));

There are similar (but not identical) bits of code all through this class; binding parameters into various bits of SQL, that sort of thing:

final String sql =
    "select "
        + StringUtils.join(MSSqlPrincipalDAO.FIELDS, ", ")
        + " "
        + "from "
        + MSSqlPrincipalDAO.TABLE
        + " "
        + "where "
        + StringUtils.join(MSSqlPrincipalDAO.KEYS, " = ? " + "and ")
        + " = ? ";
final PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, principal.getPrincipalNumber());
statement.setString(2, principal.getPrincipalSequence());

To my Python-educated eye, this looks hideous. The field names are repeated all over the place, and putting them into constants isn't any better. The bean-property to SQL column mapping is also repeated several times - very error prone. But in Java, I can't think of a cleaner, less repetitive way of doing it. Am I missing something super-elegant?

Building the Transfer Objects as Maps would be a lot prettier, I know. But then using them would be a bit painful, so I don't want to do that. :-(

Another question; I went through this code replacing all the SQL construction literals (like "select ", for example) with constants. But it seemed to me that this made the code less readable, and no more maintainable. So I'm leaving the literals in. Will the code-police be able to make a good case against me?

BTW, clearly these DAOs could be generated automatically. Are there any good tools for this? (Other than sql2java, which I've tried; I can't get it to work.) If not, I think I feel some Python coming on...

Posted to Java by Simon Brunning at 02:06 PM
Taking exception to Exceptions

Families. Can't live with them, can't legally kill them.

That's exactly how I feel about a lot of Exceptions; can't do anything about them, can't ignore them.

NamingExceptions, for example:

public static Connection getConnection(){
    try {
        Context context =(Context) new InitialContext().lookup("java:comp/env");
        DataSource dataSource = (DataSource) context.lookup("jdbc/FooBar");
        Connection connection = dataSource.getConnection();
        return connection;
    } catch (NamingException namingException) {
        log.fatal(namingException);
        throw new RuntimeException(namingException);
    } catch (SQLException sqlException) {
        log.fatal(sqlException);
        throw new RuntimeException(sqlException);
    }
}

If anything goes wrong here, then my whole application is probably hosed. So, I'm following the Bruce Eckel approach; don't throw errors if your client code has no hope of doing anything to recover. Is there anything more sensible that I can do?

Posted to Java by Simon Brunning at 01:26 PM
February 17, 2004
JSTL resources

I'm having mixed feelings about JSTL. In many ways, it's really nice. But it's a bugger to debug. And I've had trouble locating good docs.

Here's what I've found:

Is there any good stuff I'm missing?

BTW, one of the tings that I like about JSTL is that any class implementing the java.util.Map interface can have its attributes referenced by EL's dot operator. Nice.

Posted to Java by Simon Brunning at 01:40 PM
Why Python people are so nice to each other

It last night's Java Meetup, I worked out why it is that Python people are so nice to one another; we don't have braces, so we don't have brace wars.

Posted to Python by Simon Brunning at 10:40 AM
London Java Meetup

Cameron has some nice pictures of last night's London Java Meetup.

I enjoyed myself very much. It's good to get together with a like-minded bunch of nerds and really geek-out. "Hi" to everyone I meet last night. I'm not going to name names, because I'm dreadful at remembering them, so I've forgotten half of them.;-)

It appears that I'm not going too far wrong with my noddy MVC implementation. I'm not leaving anything out that I haven't already realised that I'm leaving out, nor done anything wrong that I've not already realised that I'm doing wrong.

Posted to Java by Simon Brunning at 10:32 AM
February 16, 2004
One louder

"Up to eleven" has made it to the SOED, I gather.

With a poet of Tufnel's calibre, it was only a matter of time, I suppose. I wonder when Lick My Love Pump will make it in.

Posted to Funny by Simon Brunning at 01:34 PM
What's new in Python 2.4

What's New in Python 2.4.

What about Generator Expressions? I hope that they are in there!

The new keyword arguments on lists' sort() method are also really nice, simplifying the DSU idiom. (Or is that a texture?)

Via Daily Python-URL.

Posted to Python by Simon Brunning at 12:50 PM
London Java Meetup tonight

London Java Meetup tonight - see you there!

Posted to Java by Simon Brunning at 12:08 PM
Wanted: Knoppix with Tomcat

Is there a Knoppix-like live CD available which auto-starts Tomcat? (Preferably one which is fairly easily customised by the dim-witted, such as myself.)

Posted to Java by Simon Brunning at 11:07 AM
Postal strike

Was there a postal strike over the weekend? I didn't get any cards on Saturday...

Posted to Apropos of nothing by Simon Brunning at 11:03 AM
Atheism and Education

Pupils could learn about atheism in RE. Brilliant - about time.

For a short time - and very much against my will - my eldest was in a C of E school. At one point, she asked me what I though God would think about something or other, and was totally scandalised when I told her that I didn't believe in God. "But Daddy," she said, "you have to believe in God. You're not allowed to not believe in God and the baby Jesus." I told her that she shouldn't let anybody tell her whether to believe in God or not, nor in which God to believe. Not me, not her mother, not her teachers, nobody. She should make her own mind up.

Now, she seems to believe in God about half the time, and not the other half. Which is just as it should be for a seven year old, I'd say.

Me, I'm an Atheist, and I have been for as long as I can remember. It's just the only thing which makes any sense to me. Any kind of God seems to require more of an explanation than It/He/She can provide. (And just don't bring up Pascal's Wager. Just don't.)

But I'm not a Dawkinsite. I admire the man as a scientist, but I don't actually believe that religion is a positive source of evil as he seems to do. For me, religion is mostly morally neutral. Good and bad people behave as they wish, regardless of their religion or lack or it. Good people can find rationale in their religion for doing whatever it is they would have done anyway, yes. But then, people seem to be able to use religion as a rationale for anything.

Posted to The Big Room by Simon Brunning at 10:42 AM
Windows 2000 source

You've heard that it's out there; well, here it is.

Via Tangent.

Posted to Funny by Simon Brunning at 10:18 AM
Lost in Translation

I saw Lost in Translation yesterday, just off Leicester Square. A brilliant film, I thought, but extremely bleak. A more evocative exposition of loneliness I can't remember. Don't see it alone!

Scarlett Johannson and Bill Murray richly deserved their Baftas, I must say. (This morning on Radio 4, I heard someone opine that Murray's Bafta wouldn't lead to an Oscar, because 'best actor' awards aren't often handed out for comedy roles. Comedy!? Did they see the same film as I did?)

BTW, Leicester Square was a mistake yesterday - it was heaving.

Posted to Music and Film by Simon Brunning at 09:55 AM
February 13, 2004
Friday the 13th

Eeeek! It's Friday the 13th! Nothing untoward has happened so far, but it's early days yet...

Besides, the true horror will be the utter lack of cards tomorrow. A friend of mine is going to a singles' party tomorrow night, but I think I'd find that too depressing for the retention of sanity.

Posted to Apropos of nothing by Simon Brunning at 03:18 PM
Firebird is dead

Long live Firefox!

Firebird Firefox bits and bobs: Open external links in new windows or tabs, Optimizing Mozilla Firebird and a Firefox Spell Checker.

Anyone else having trouble getting themes?

Posted to Software by Simon Brunning at 11:57 AM
I may have to get new mobile

I've been surprisingly uninterested in mobile phones in the past. I've been more than happy with my pay-as-you-go Nokia 3110.

But that may be about to change. Very cool stuff.

Posted to Python by Simon Brunning at 10:05 AM
February 12, 2004
HTTP Compression for Servlets

Via boncey.org, a fab little little Servlet Filter trick in Two Servlet Filters Every Web Application Should Have.

Posted to Java by Simon Brunning at 03:15 PM
PDF generation

Scope creep; it'll get you every time.

An important part of the system that I'm currently working on is a financial statement. This needs to be printable, and to look good when printed. To begin with, I was confident that CSS styled HTML would do the necessary. But now I find that we need this statement to look exactly the same as the paper one that users currently get, including things like fonts and the location of page breaks. Also, the client now wants cross referencing; "See page 12 for a breakdown", that kind of thing. So, HTML ain't gonna cut it, CSS or no CSS. Sigh.

Naturally at this point, we looked at PDF. We can do all the above and more with PDF. But how to generate it?

Generating PDF is nothing like generating HTML. It's a binary format with all sorts of indexing and cross referencing. You can't just use a template tool like JSP or Velocity. (In fact, it's a sort of wrapped and compressed Postscript. Postscript is actually an executable format.) So, we need a tool to generate our PDF for us. (The tool doesn't have to be for Java/J2EE, though that would help.)

Naturally, I looked at Reportlab. Their RML2PDF tool is exactly what we are looking for; we could easily generate the required RML (an XML dialect) file from a JSP. But, look at the price! RML2PDF is simply way beyond our budget. Sorry, Andy. :-(

Some of the other commercial offerings are rather a lot cheaper. Style Report, for instance, can be driven from Java objects or direct from SQL, and includes a JSP taglib, so it would fit right into our current architecture. Mark is evaluating tis product, along with ReportMill, Formula One e.Report and Crystal Reports. If anyone has used any of these, please let us know how it went!

On the OSS front, iText looked promising, but we aren't allowed GPL software on our products. (No, not even LGPL software; its meaning is ambiguous in the context of a Java application, and we don't intend taking any risks.) The other OSS tools either had the same license issues, or were at too low a level, or both.

So, what does everyone else use?

Posted to Java by Simon Brunning at 03:06 PM
February 10, 2004
Trust the PDA

The PDA is your friend.

If you've never experienced Paranoia, well, you've missed out. You were probably too busy going out, making friends, boozing and partying, that kind of thing. I feel sorry for you.

To be honest, actually it was more fun reading the Paranoia modules that it was playing the game, but, hey?

Posted to Funny by Simon Brunning at 05:06 PM
MVC the noddy way

Speaking of our noddy MVC framework, it's all coming together now.

The bleedin' obvious stuff: we have a Controller servlet, to which all *.command URLs map. The Controller loads up a Map when it starts up, mapping URLs to Actions. An Action consists mainly of a class implementing an interface; ControllerAction. The Controller instantiates this class, and calls its doAction() method. The request and response objects are passed into this method, giving the Action access to everything that it needs.

So far, so good. But this is where is starts to get a little complex. What happens next?

We need to redirect (or forward) the client on to the View, usually a JSP, at this point. But we'll need to pass some information from the Action to the View. How do we do this? We are just returning a ControllerActionResult object from our ControllerAction.doAction() method, and stuffing this into our session. This is working so far, but I'm worried.

Also, to which View should we redirect? Initially, we were just going to keep this in the Controller's Action mapping, but of course, you might want to redirect to different JSPs depending on what the Action thinks. Do you just have a fixed number of potential target Views? Say, one for a successful Action, another for a used error, and another for an unexpected error? What if you need more options than this?

At the moment, our ControllerAction.doAction() method is passing back the target View as an attribute of the ControllerActionResult object, and we redirect according to this. This works OK, but will it scale?

Oh, BTW, we have decided that we will use JSTL's SQL taglib to present our financial data. To our application, it really is just a bunch of numbers, so building a Model is just unnecessary work. YAGNI. ;-)

Posted to Java by Simon Brunning at 04:45 PM
London Java Meetup

There'a another London Java Meetup on the 16th. I'll be there, boring everyone to tears, talking about my noddy MVC stuff, JSTL, and, err, drinking beer.

Remember: it's newbie friendly!

Posted to Java by Simon Brunning at 04:25 PM
February 07, 2004
Paddington again...

This time, I'm waiting for Freja and Ella to arrive. They'll be here in ten minutes or so. The Centrino/Toshiba stand is still here, so I thought I'd have a little blog.

Cool little notebooks; but not as cool as Andy's iBook!

Posted to Apropos of nothing by Simon Brunning at 03:58 PM
February 06, 2004
Who next?

Jamie Oliver, Tony Blair, who next?

Posted to Blogs by Simon Brunning at 02:32 PM
What's wrong with J2EE

Mike Clark and Glenn Vanderburg have been pondering J2EE's complexity.

Now, I've been buried up to my neck in J2EE for a while now, and from this position it's easy to loose sight of the big picture. We are using lots of neat toys, each of which helps me out in one way or another, so I'm happy to have them. Since they really do all help, I'm right to be happy.

El Presidente, though, looks upon this huge list with more than a little trepidation. And he's right too; we are using a lot of tools, many of which are fairly complex. By rights, our project is a fairly simple one. What do we need all this stuff for? (And we've kept the list as short as we comfortably can, believe me!)

Well, J2EE is at least part of the problem. A simple 'Hello World' application isn't, well, simple in J2EE. Servlets, JSPs, the deployment descriptor, the WAR file, the context, and so on.

You might argue that this is because J2EE isn't designed for simple applications. And you'd be right; it's designed for complex applications; it scales well. This is true up to a point. But. But if it scaled that well, we wouldn't need all this other stuff, would we? (An MVC framework, a persistence layer, additional taglibs, etc, etc, etc.)

(OK, so, I know that J2EE has its own persistence layer: EJBs. But I've been warned off them so many times I didn't even consider them. Also, The new JSP 2.0 includes the JSTL, removing much of the need for external taglibs.)

But the other side of the problem is Java itself. I think that at heart, Glenn has it right. Java is not amenable to extension, and J2EE extends it well beyond what ESR refers to as its 'functional envelope'.

Python doesn't have a J2EE, but if it did, I suspect that it would be far simpler.

Still, I can't say I'm not having fun with all this stuff, so it isn't all bad. ;-)

Posted to Java by Simon Brunning at 02:01 PM
February 05, 2004
UK Python Conference 2004

It's on. Which is good.

The bad news is that unless my finances take a radical turn for the better within the next two months, I'll not be going. :-(

My company has no interest in Python, so it'll be self financing or nothing.

Posted to Python by Simon Brunning at 05:01 PM
South London Boys

Steve, Andy, Michael and I will be meeting up for beer, curry and conversation at The Tup, Balham on Friday evening. All welcome.

I'll be suggesting The Lahore Karahi in Tooting for the curry.

Posted to Apropos of nothing by Simon Brunning at 01:14 PM
Python: The Programming Language for Nice People

Alan Green: "In general, the Python blogging community is full of interesting people, who are capable of expressing themselves clearly, who are polite and who can respect alternative points of view. Does the language rub off on the people or do the people rub off on the language?" Modesty forbids my linking directly to Alan's post. ;-)

Well, I can't answer the question, but I will point out that it's not just the blogs; comp.lang.python is also full of exceptionally nice, helpful people. So, there is certainly some kind of link here...

Posted to Python by Simon Brunning at 12:57 PM
Log4j and J2EE

I've not used log4j in anger before. Now I am, and I must say; it rocks. simple and powerful.

One question, though. Where should you put your log4j.properties file? The usual place seems to be in your /WEB-INF/classes directory, but I have two problems with that.

Firstly, it's not a damn class. OK, OK, I should probably just get over that one - /WEB-INF/classes is your basic runtime class path, whatever it may be called.

Secondly, and more seriously; if you ship your application as a WAR file, you can't get at it to edit it, which is a real problem.

Any suggestions?

Posted to Java by Simon Brunning at 12:45 PM
February 03, 2004
DBTags

Sigh. I was just about to mention how cool and useful the DBTags tag library is, when I find that it's deprecated, and that I should be using the JSTL instead. Bugger.

The JSTL is implemented by Jakarta.

Posted to Java by Simon Brunning at 10:36 AM
Terror law

In a further hardening of his earlier proposals, Home Secretary David Blunkett has proposed that suspected terrorists be convicted on the basis that a representative panel of Daily Mail readers "doesn't really like the look of them". He went on the point out that "honest, decent citizens need not worry about these proposals, since they will naturally only apply to darkies. Oh, shit, did I say that out loud?"

Robert Mugabe responded: "When I said that I'd teach the British a thing or two, this wasn't what I had in mind."

Posted to The Big Room by Simon Brunning at 09:47 AM
February 02, 2004
The cult of competence

"A new survey says one in 10 people are incompetent".

Hey, what are you looking at me for?

Posted to Funny by Simon Brunning at 01:05 PM
Sticking it to The Man

School of Rock. It does.

Freja, my Father and I all went to see School of Rock this weekend, and all three generations enjoyed themselves immoderately. Recommended to everyone - though if you are or have been a fan of rock, you'll get more out of it. Think of it as Spinal Tap for all ages. And there's no praise higher than that.

A couple of weeks ago, the girls and I saw Freaky Friday. As expected from a Disney flick, there was a certain amount of cloying sentimentality. But unexpectedly, it's also very funny. Jamie Lee Curtis' teenager is fabulous. Go. You'll laugh.

Posted to Music and Film by Simon Brunning at 12:33 PM
Freja's verdict

Freja's major critisism of this site was that there were none of her creations here. So, to rectify this, here's one of Freja's pictures, and one of her poems:

MY  SCHOOL  IS  CLOSED

 MY  SCHOOL   IS      CLOSED .  
IT’S    TIME    TO    PLAY.
SNOW!

LET’S    MAKE   A  SNOWMAN!
LET’S      MAKE  A   SNOWMAN!
COME   OUTSIDE!
COME  OUTSIDE!
SNOW!
PLAY!
BUMP!
FUUUUUUUUUUUUUUNNN!  WHEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE!-


(This is as faithful a rendering as I can manage of a Word document that she created this weekend.)

Posted to Parenting by Simon Brunning at 11:11 AM
A Decimal Data Type - PEP 327

PEP 327 appears to be exactly what I've been hoping for - an immutable decimal data type in the Python standard library.

+1 from me. ;-)

Posted to Python by Simon Brunning at 10:42 AM
Fitzrovia

Fitzrovia? Never heard of it!

But never mind that. I'm meeting Steve, Andy, Kelvin and possibly others this evening at The Bricklayers Arms, Fitzrovia (near Tottenham Court Road tube). All welcome.

Posted to Apropos of nothing by Simon Brunning at 09:37 AM
February 01, 2004
For Freja

Freja and I are at Paddington Station, and we're just about to get on the train. I'm blogging from the Intel Centrino stand, 'cos Freja wanted to see how I create my site.

These notebooks are pretty cool - shame I can't afford one!

Posted to Apropos of nothing by Simon Brunning at 04:41 PM