magpiebrain

Sam Newman's site, a Consultant at ThoughtWorks

Archive for ‘November, 2003’

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.

Advertisements

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…