Friday, August 26, 2011

Smart or beautiful?

Method API has to be clear about return values. It can either return value or throw an exception. But when it does both this gets really confusing. Take a look at the Java's  java.io.File.createNewFile() signature:

> boolean createNewFile() throws java.io.IOException

This method returns true if "the named file does not exist and was successfully created; false if the named file already exists".

The problem with this approach is that when exception is thrown we get no return value. Has the file in fact been created or not? Not clear. And if we have to check for exception in order to find out this, the method is better be void. Ideally, with unchecked exception.

> void createNewFile();

Just like that. And we do want to check, we check for exception.

try {
      createNewFile();
} catch (IOException e) {
      // file not created. 100%. Guaranteed. No need to look at something else.
}




Tuesday, January 25, 2011

Monday, September 18, 2006

Sunday, September 17, 2006

Saturday, August 19, 2006

  Posted by Picasa

Bournemouth Beach

Monday, May 15, 2006


Oracle Shopping Centre, Reading Posted by Picasa

Wednesday, March 29, 2006


Reading University Posted by Picasa