Monday, March 08, 2004

Transferring scripting idioms to Java - General Philosophy


I’ve used the words simple and concise to describe the goals of this library. It’s worth spending a few sentences on what I really mean by this. In my mind a class library is simple and concise if it allows you to do what needs to be done in a minimal set of understandable steps without a lot of support code. That may not be a very deep explanation but its all I mean.

One of the simplest ways this library keeps support code to a minimum is to generally throw unchecked exceptions instead of checked exceptions. Unchecked exceptions can still be caught and processed if required but handling them is optional. I don’t recommend this approach for all class libraries but for the domain of simple utilities I think it’s a good fit.

Another way this library reduces code is to rely in heavily on functors. Functors are as close as approximation I know of in Java to true scripting language blocks and closure. By relying on functors to represent the inside of an IO processing loop the library can wrap and package all the standard setup and teardown code needed to do IO. The following is a example of functors interface.

* This interface describes a function that takes a single String object as a parameter.
* Its intended to be used in a manner similiar to a c or c++ function pointer.
public interface IStringFunctor {
* The main entry point of the functor
* @param s - the string to be operated on
Object call(String s);

Post a Comment
The Out Campaign: Scarlet Letter of Atheism