Sunday, 23 November 2008

What would you ask?

Had lunch with a friend of mine today. She's writing a book and asked me if I could ask any question of anyone living or dead, real or fictional what would it be and who would I ask?

I really had to think about it. My first thought was to ask president Bush if he planned and allowed the attacks on September the 11th.

Then I started to think a little less seriously. I'd quite like to ask Freddie Mercury why he wasn't more careful. And of course there are my fantasies about a certain character from a certain science fiction series.

Finally I decided that Peter TÃĪgtgren from Hypocrisy and Pain had it right with the song Roswell 47 from 1996's Abducted album. I'd really like to ask Harry Truman what really happened in Roswell in 1947.

Saturday, 22 November 2008

ACCU Mentored Developers Effective Java Project

I've just created a new blog for the ACCU Mentored Developers Effective Java Project: http://accu-mentored-ejava.blogspot.com/

Friday, 21 November 2008

Taming the Lint Monster Review

Now it's dark so early it's quite exciting rolling past Canary Wharf on the train and seeing all the lights and thinking of Lehman building standing empty. It still fills me with excitement, just like the first time I went there for a job interview. Anyway, I wasn't in London last night to see Canary Wharf. I was there to see Anna-Jayne Metcalfe speak about PC-Lint.

Although it pains me to say it and the possibility of a C++ project came up just this week, I don't do C++ any more. The last two years have been a really big change for me in that regard. However, I am more than a little responsible for the fact that Anna is speaking in London tonight, having volunteered her to Allan Kelly when he was looking for a speaker for November, so I went to show my support and take any flack.

Anna had a really good turn out. ACCU London meetings usually attract between ten and twenty attendees and Anna had somewhere between ten and fifteen. She was obviously nervous and at times difficult to hear, but she knows her stuff and has a passion for it. I was also impressed that she managed not to mention her company's Visual Lint product until the question and answer session at the end.

The group were intensely interested and questions were asked throughout. Although it was looking unlikely at one stage, Anna did manage to get to the end of her slides and there was only a slight overrun, that wasn't helped by technical problems at the beginning.

I found it quite nostalgic revisiting memory leaks, uninitialised variables and other problems that PC-Lint can detect and that, in the world of dynamic garbage collected languages, I rarely need to worry about in quite the same way these days.

I'm hoping Anna will speak at the ACCU conference this year and give us an insight into Visual Lint and Riverblade's new Incredibuild integration.

Boiler Plating Database Resource Cleanup - Part I (v2)

This is a modification of my original Boiler Plating Database Resource Cleanup article giving a bit more background, exploring a couple of different ideas and setting the sceane for the second part:

The problem is simple. Cleaning up after querying a database in Java is unnecessarily verbose and complex. Plain and simple. I'll start with an example that demonstrates the problem. The system I'm working on currently uses a number of web services. We have a set of web services on the production box, another on the development box and another on our local machines. The system asks the relevant database for the location of the web service based on the services' name:

try
{
Class.forName(driver);
Connection con = DriverManager.getConnection(connectionString,username,password );
try
{
PreparedStatement ps = con.prepareStatement("select url from services where name = 'Instruments'");

try
{
ResultSet rs = ps.executeQuery();
if(rs.next())
{
System.out.println(rs.getString("url"));
}

try
{
rs.close();
}
catch(SQLException e)
{
// Report Error
}
}
finally
{
try
{
ps.close();
}
catch(SQLException e)
{
// Report Error
}
}
}
finally
{
try
{
con.close();
}
catch(SQLException e)
{
// Report Error
}
}
}
catch(Exception e)
{
// Report Error
}

This is a lot of code to get one string out of a database and most of it must be repeated every time a database is accessed. Most of it is error handling and resource management. In fact I've over simplified it. For a discussion of how error handling and resource management should really be handled see "Handling Exceptions in Finally" mentioned above.

The Sun Java Documentaton states the following for the Connection interface's close method:

Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released.

Note: A Connection object is automatically closed when it is garbage collected. Certain fatal errors also close a Connection object.

It also states the following for the Statement interface's close method:

Releases this Statement object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. It is generally good practice to release resources as soon as you are finished with them to avoid tying up database resources.

Note: A Statement object is automatically closed when it is garbage collected. When a Statement object is closed, its current ResultSet object, if one exists, is also closed.

And the following for the ResultSet interface's close method:

Releases this ResultSet object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.

Note: A ResultSet object is automatically closed by the Statement object that generated it when that Statement object is closed, re-executed, or is used to retrieve the next result from a sequence of multiple results. A ResultSet object is also automatically closed when it is garbage collected.

This can all be interpreted in a number of two ways. The first is that everything gets closed when it is garbage collected, so there is no need to explicitly close anything. This relies on the appropriate finalizers getting called but, as Bloch tells us, Java provides no guarantee that a finalizer will ever be called, even when an object is garbage collected.

Another method is to explicitly close Statement and Connection objects as statement objects clean up their associated ResultSet objects. Drawbacks include any error caused by closing the ResultSet is potentially ignored and the resource is not release as soon as it could be.

Yet another method is to explicitly close everything. This is the most code, but releases resources and handles any error as soon as a resource is finished with, making it most efficient way of using resources.

I favour the third and final method. It is more code, but boiler plating will mean most of it only need to be written once. Everything will be cleaned up as soon as possible, all errors can be trapped and reported and nothing is left to chance.

The close methods for Connection, Statement and ResultSet objects can all throw if there is an exceptional circumstance. In Item 65 of Effective Java Bloch explains that exceptions should not be ignored. He also describes certain circumstances where it might be ok to ignore or log these types of exceptions. The Connection, Statement and ResultSet close methods could be considered one of these situations.

Read more.

Wednesday, 19 November 2008

[Accu-london] Taming the Lint Monster (20th November)

Speaker: Anna-Jayne Metcalfe
When: 7:00pm, Thursday 20th November 2008
Cost: Free. Open to non-members.
Where: 7city Learning, 4 Chiswell Street, London, EC1Y 4UP
Map: http://www.7city.com/pdf/chiswell_street.pdf

Registration is required for this event due to limited space and
security at 7city. Reserve your place by e-mailing James Slaughter,
slaughter@acm.org.


About the Talk
If used effectively, code analysis tools can make a huge difference to the quality of a codebase and its perceived reliability and maintainability. However, in the C++ world, the one static analysis tool which is most established - PC-Lint from Gimpel Software - is also probably the hardest to configure and use. Consequently, many organisations who have purchased it do not use it effectively (if at all).

This session aims to present a practical introduction to PC-Lint from the perspective of how to configure and use it effectively to improve the quality of C and C++ codebases. Using a combination of theory, discussion and live demonstrations, topics such as setting up a PC-Lint analysis configuration, troubleshooting analysis problems and interpreting the mass of analysis results which can easily result from the first contact of PC-Lint with a "virgin" codebase will be covered in some depth.


About the Speakers
Anna-Jayne Metcalfe is the founder of Riverblade, an Independent Software Vendor specialising in code analysis tools and Visual Studio integration. Prior to that she worked extensively within the defence and marine sectors, developing (among other things) the concept of the "virtual super instrument" in avionic functional testing, and a market leading sub-sea acoustic positioning system.

Anna holds a BEng in Electronic and Electrical Engineering from Surrey University in Guildford, but moved from hardware to software design in 1996 when the opportunity arose to lead a team developing virtual instrument software for an avionic functional test system. She has published several articles on codeproject.com, and can usually be found hanging out in the Lounge there - where her affinity for chillis, Belgian beer and stotty cakes is far too well known to the other inmates.


More Information
Additional details can be found on the ACCU website at:
http://accu.org/index.php/accu_branches/accu_london

Tuesday, 4 November 2008

Amber Cottage Whitby

For the Whitby Gothic Weekend this year I stayed with some friends at Amber Cottage. It's a compact, comfortable and utterly delightful little house. It has very good heating, a reasonable shower and Sky (FreeSat) TV! It's ideal for a small family or group like us.

The only downsides are that there is very patch mobile coverage (none at all if you're with Vodafone. T-Mobile seems to be fine though) and there's no door between the lounge, the hall and the top bedroom. But I'm really struggling to find anything negative to say about it.

I'm hoping to go back. Many times.

Whitby Gothic Weekend October 2008

I love going to the Whitby Gothic Weekend and this year was as much fun as it's ever been. I took a friend of mine who had never been before (a Whitby virgin no-less) and she loved it, although I did manage to drink her under the table on the Saturday night.

For the first time I didn't do the official Whitby. My friends and did the alternative Whitby which, for us, turned out to be lots of drinking in pubs a brief trip to a "bleepy" goth night, more drinking in pubs and finally Sexy Sunday.

I think the highlights were catching up with old friends, the Sunday night in the pub, followed by Sexy Sunday and, of course, Lewis Hamilton winning the formula one divers championship. Although I nearly missed the entire race as I was on the phone to my wife.

I seemed to do even more talking than previous years and have made even more new friends. Roll on 2009.

Abigail Williams is Not a Name for a Black Metal Band...

...or at least that's what I thought until just now when I looked them up with google to find a link for this blog post. It appears that Abigail Williams was one of the foremost accusers in the Salem witch trials of 1692.

Abigail Williams are also a surprisingly good Black Metal band. I thought I'd passed through my black metal phase a while ago, but these have a bit of an extreme metal edge (think Dark Tranquillity, Arch Enemy) which is really my thing at the moment. The first mini album Legend is like early Cradle of Filth (when they were good) and the new release, In The Shadow of A Thousand Suns, could not sound much more like Emperor if they tried. I love it. Give it a try.

Marauder File Viewer 0.0.0.2

Download


You can download the latest version of the Marauder File Viewer here. I have implemented the following features since the last version:

  • RDF layouts
  • Saving and opening of projects
  • Plugins

It is now possible to develop plugins for the Marauder File Viewer by implementing a few small interfaces. If you would like details or have comments, please email me: paul.grenyer@gmail.com.

I'm working on searching and layout manipulation for fixed length file layouts next.