mardi, avril 24, 2007

Exceptions, the Widest net effect and a new Exception catching syntax

One annoying thing with Exceptions Catching in java is obviously the fact that a lot of APIs still throw checked Exceptions (not inheriting from java.lang.RuntimeException) to your face, therefore forcing you to deal systematically with things that sometimes cannot be recovered from in your application.

This often used to imply the horrible "wide net" effect, when one uses too wide a net to catch exceptions (and even sometimes never dealt with them in order to get rid of them... but this never happens anymore :P ).

One interesting and possibly easy to integrate evolution to the java language would be the possibility to catch multiple exceptions in one go as follows:

catch([MyException,AnotherException] e){
    throw new WrapperException("Something bad occured in my code, but I won't deal with it, though this gives you a context ;)",e);
}


In this case, in current java constructs, this would end up with:

catch(MyException e){
    throw new WrapperException("Something bad occured in my code, but I won't deal with it, though this gives you a context ;)",e);
}catch(MyException e){
    throw new WrapperException("Something bad occured in my code, but I won't deal with it, though this gives you a context ;)",e);
}


Or more probably because nobody likes repeated code:

catch(MyException e){
    dealWithException(e);
}catch(MyException e){
    dealWithException(e);
}


Or even for lazy people:

catch(Exception e){
    throw new WrapperException("Something bad occured in my code, but I won't deal with it, though this gives you a context ;)",e);
}


I vote for it... do you? ;)

mardi, avril 17, 2007

TDD, TET, and TTD...

As I am quite test infected these days, I tend to make my tests run AFAP (As Fast As Possible...).

This is quite an important topic when dealing with UNIT tests. In fact it's as much crucial as encapsulation of the System Under Test. If your tests run fast, you'll run them often. Hence the "make your tests run AFAP with a good TET (Test Execution Time) when using TDD (or not).

This is not quite new and has been advocated by anonymous people like Martin F. (Except for the TET part which I own a copyright for.... not...)

This is where enters TTD.

I found myself reverting from an everyday use of MyEclipse with JBoss 4.0.x to a WTP 1.5.x/JBoss 4.0.x pair.
And believe me... it's hell on earth! I was trying to explain to a colleague of mine how Struts 2 (interceptors... etc) and Spring work together, and believe me, it's really hard to demonstrate anything efficiently when you never know the status of your deployments and when a modification of a files "sometimes" triggers an awfully slow ant task making a full redeployment of the web application!

So it really seems that TTD (Time to deployment) affects a lot the productivity of a developer. Yet again nothing new, but it is very disappointing to see how a tool like WTP handles such a crucial task.

My conclusion is that I'm working right now on a "Workspace to File system synchronizer" allowing to keep part(s) of your workspace in sync with another part of the file system (for example a folder in JBoss's deploy folder, or in Tomcat's webapps folder) hooked on the Platform's events.

This way, with a great TET and a marvellous TTD, I'll be able to attain my goals ASAP.