Java Modules

It looks like the Java community is finally going to do something about packaging Java applications and libraries — JSR# 277. Better late than never, I suppose.

[via: CodeQ]

Lawrence Lessig and John Hardwicke Fight Sexual Abuse and the American Boychoir School

Lawrence Lessig and John Hardwicke Fight Sexual Abuse and the American Boychoir School is a deeply disturbing story but one well worth the reading.

Mr. Lessig speaking of the man who sexually abused him and the people who knew about it.

"I've never felt angry, or really angry, at Hanson. Hanson's sick. He's got a disease. The real evil isn't the Hitler. The evil is the good German. The evil is all those people who could've just picked up the goddamn telephone and stopped it."

I have never been in a situation that even compares to this one but I hope that if I ever am I will do the right thing, regardless of the risks.

Martin Fowler on LOP

Martin Fowler has done a nice write up about Language Oriented Programming and the breed of tools, that have recently appeared, to support it.

RE: Dynamicity and Throwing Money at Problems

Brian McCallister has in interesting post on how XML is used by the Java community. I think he is right about the fact that most of the XML dialects being used in the Java world go against the grain of Java. However, I think they are not being used for dynamicity, at least by his definition. Sure the dynamicity argument is there but it is a red herring because, as Brian points out, no one actually uses the dynamicity. What these Java developers are really doing is creating domain specific languages. They need to do this because, in many cases, the equivalent functionality written in Java would be an excessive amount of code.

And there-in lies the rub, if using plain Java is too expensive and hard to maintain then the logical thing to do is to switch to language in which solving your problem is not too expensive and hard to maintain. Unfortunately, most Java developers either A) are not allowed to even consider using a language other than Java or B) have some emotional ties to Java. If A is true the logical thing to do is to write the language you really need, and want, but to call it “configuration” so that it sounds like you are still writing the app in Java. If B is true the logical thing to do is to write the language really need but to call it “configuration” so that it sounds like you are still writing the app in Java. Notice that those two are pretty much exactly the same. Either way you end up with a custom programming language specific for your domain and you call it “configuration” even though the contents are obviously source code.

Why Java is Not My Favorite Language — Reason #39

Java is early bound. Early binding is an optimization which, like most other optimizations, it is almost always premature. This particular premature optimization causes significant amounts of superfluous code. For example, assume that we the following API for writing to a log file.

class Logger
{
    public void log(Object obj) {...}
    public void log(Throwable e) {...}
}

log(Object) writes the results of obj.toString() to the log file and log(Throwable) writes e.getMessage() and a backtrace. Now I want to wrap this API in my class so that when something goes wrong I can do some clean up, in addition to logging the fact that something went wrong. Sometimes my code detects problems by catching an exception and other times by explicitly checking for certain conditions. So I write the following method and call it every time I detect a problem, either with the exception or with a string that describes the detected problem.

private void handleError(Object description)
{
    // do clean up
    myLogger.log(description);
}

Because Java is early bound this handlerError() method always calls Logger.log(Object) even if description is actually a Throwable, which means I never get the backtrace in my log file. To make this work correctly I have to write multiple version of the handlerError() method or add some instanceof checking and casting just to inform the compiler of the object type. Either way that extra code adds no value to my application and I hate writing code that adds no value to my application. Unfortunately, I feel like I end up doing that a lot in Java.