magpiebrain

Sam Newman's site, a Consultant at ThoughtWorks

Posts by samnewman

Of late, I’ve been looking into a variety of technologies, with a view to reimplementing an existing web application. “Spring”:http://www.springframework.org and “Hibernate”:http://www.hibernate.org/ are a given. Even if it offered no performance improvements over CMP Entity Beans, Hibernate is much nicer to work with. Once you get your head around Spring, its benefits become clear – cleaner, simpler code with less configuration hassles can only be considered a good thing. Next up I’ve been looking at business rule engines and user interface scripting.

Currently, both “Jess”:http://herzberg.ca.sandia.gov/jess/ and “Drools”:http://drools.org/ are striving for my attention, with Drools wining out so far purely because of its better documentation. Both should theoretically allow me to remove business rules altogether from my Java code, assuming I can work out a design whereby everything hangs together properly. For the UI, I had almost come to the conclusion that I would be hand-scripting it, but I took a look at the “Thinlets”:http://www.thinlet.com/ project, and was impressed by what I saw.

From the website:

Thinlet is a GUI toolkit, a single Java class, parses the hierarchy and properties of the GUI, handles user interaction, and calls business logic. Separates the graphic presentation (described in an XML file) and the application methods (written as Java code).

Its compressed size is 38KB, and it is LGPL licensed.

Thinlet runs with Java 1.1 (browsers’ default JVM) to 1.4, Personal Java, and Personal (Basis) Profile. Swing isn’t required.

The online demos look impressive. My only concern at present is the requirement for a Java plugin. Assuming this isn’t an issue for my target audience (and it depends greatly on which of the projects I take on – there are a couple on the table) I may well consider using it. It certainly helps support the argument that a thin (web) client can also be a rich one.

Dan is making posts via a neighbours wireless network, who seems to have no idea what’s going on. This scares me. I think I’ll hold off going wireless for the moment.

I’ve stayed out of much of the recent debate concerning Exception handling, mostly because I realised I didn’t have much of an opinion on the subject and suspected that even if I did the code I wrote probably didn’t match what I thought I should be doing. To be honest I kind of handle exceptions without any real thought, and after reading Gunjan Doshi’s article “Best Practise For Exception Handling(ONJava.com: Best Practices for Exception Handling [Nov. 19, 2003])”:http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html realised that at least as far as he was concerned, I certainly have room for improvement. Looking over my code after reading the article I’ve noticed that I have been correctly catching user-caused exceptions and erroring appropriately – given that 90% of these errors are caught in validation code its not that surprising. With exceptions generated due to programming errors or problems with resources I’ve noticed a couple of areas where the user has not been properly informed that something has gone decidedly wrong – a few of the exceptions are simply being consumed, logged, and ignored.

Concerning the Checked exceptions vs. Unchecked exceptions debate I’ve always been a big fan of checked exceptions. This probably stemmed from my C programming days when many a programming error was caused by forgetting to check the return type of a system call for an error code. Checked exceptions ensure that at compile time the programmer has taken some action to deal with the result. Gunjan is of the opinion that the only point in throwing a checked exception is when the client can actually do something about it, which is an approach I can certainly understand. Again carrying out a brief audit of my code I have found that all too often I am throwing checked exceptions purely to make sure I catch and handle them in my code rather than giving any real thought to if they should be unchecked. All in all, the article is a good read, and whilst it may not end the debate on the subject of proper exception handling it may at least raise some interesting approaches.

When attempting to understand a new concept, for most of us there comes that moment of clarity where the new concept just ‘clicks’. We go from a muddled understanding of a new idea granted by wading through manuals, listening to explanations or even banging our heads against a brick wall, to getting to an underlying clear realisation of what the thing actually is. I still remember back at university when I first understood how the command-listener pattern worked (and at the time how patterns as a whole were useful), or the watershed moment when sed’s regular expressions looked less like hieroglyphics and more like the answer to so many prayers.

More recently I’ve been searching for the same level of understanding with a few topics, however I’ve only been partially successful. My “Hibernate”:http://www.hibernate.org/ application works perfectly, and I am happy to carry on developing it, but a underlying knowledge of how Hibernate itself works still escapes me (this is mostly due to laziness however – Hibernate just works so I lack the desire to dig any deeper). Things with the “Spring Framework”:http://www.springframework.org/ in some regards has gone a little better, however the MVC web framework still seems overly complicated and at times a little muddled (although this could be down to my years of Struts use). Finally, my dabbling with CSS has resulted in some nice results, however most of this has be achieved by hacking other peoples code around – half the time I don’t really know what I’m doing with it. I’m starting to worry that as I get older my ability (and to some extent desire) to properly understand new concepts is diminishing. Either that or I’m just lacking the time to properly put in to these new projects – most of this has been done in my spare time.

Come the New Year, I think I’m going to have to think more deeply about what I actually want to do with myself – work hasn’t raised a new challenge for me in months and I’m worried that my brain is starting to atrophy. In the meantime lots of new technology is being released and is passing me by – but I suspect I’m not the only person in this situation.

Well, it finally seems to be coming together. I have a build that creates a very simple webapp (can create 1 single object type) using “Hibernate”:http://www.hibernate.org for persistence, “XDoclet”:http://xdoclet.sourceforge.net/ to generate Hibernate mappings, and “Spring”:http://www.springframework.org/ to pull it all together. The build is quite frankly a mess (its an amalgamation of about 3 example build scripts with my own hacks thrown in for good measure). I’m going to get the build tidied up a bit, then on to the next challenges – integrating Session beans, web-services, and of course documenting the whole thing. It seems I’m a glutton for punishment…

As a result of my research into “Hibernate”:http://www.hibernate.org that I’ve been doing over the last couple of weeks, I can across enough references to the “Spring Framework”:http://www.springframework.org/ for me finally to give it a look. I was quickly hit by the wealth of information out there, however nothing really provides a good concise overview – the Spring Framework “tutorial”:http://www.springframework.org/ for example is a 48 page PDF which gives an overview of each package in turn – not my idea of a tutorial at all. There seems to be an inordinate amount of waffle on the subject – looking at the petclinic example in the distribution, I can understand some of Spring’s power, but at the same time it can be very confusing. I’m fairly sure I can come up with a more concise getting started guide, which I’m going to aim to do over the next week or so.

Thanks to “kdub(kdub’s log)”:http://www.jroller.com/page/kwiersma/20030519#hibernate_xdoclet_tutorial, I spotted Mark Eagle’s tutorial on using “XDoclet and Hibernate(Object to Relational Mapping and Relationships with Hibernate)”:http://www.meagle.com:8080/hibernate.jsp (warning: seems to be running of someones app server on port 8080 – I’m grabbing a copy in case it vanishes). If it works as advertised then it could really speed up development time for me. Rather than generating the JavaBean from the mapping files, it generates the mapping file from the JavaBean sources. I’ll let you know how well it works…

_Updated 9:35am_: As feared, the site hosting Mark’s tutorial has gone AWOL. I’ll attempt to contact him to see if he wants me to host it for him…

I hope to get a rough performance comparison of an enterprise application using entity beans for persistance compared to using Hibernate soon, in the meantime I thought that a brief comparison of the development effort involved in using the two approaches might be in order. Comparisons are based on JBoss 3.2.2 running MySQL.
Continue reading…