01 June 2009

Effective Java

I just finished re-reading Effective Java by Joshua Bloch.

Most of the problems described in the book do not have super subtle roots. When you read about each issue it is easy to understand in retrospect the source of the problem and how to avoid it. Yet, and this is really sobering, even the designers of the Java libraries made many of the mistakes described (the book has lots of Java war stories). And they are still paying for some of them so that they can maintain API compatibility. This book represents a lot of collective experience that Java programmers have acquired over the years. So it's really valuable to have all these tips in one place. In addition, Bloch's writing is fantastically lucid, one of the best among all technical books I've read.

I had read Effective Java before but now that I'm actually working on some big Java projects (for work, not hobby) I think I had a much higher absorption rate than before.

I had the first edition of Effective Java on hand, which was written for Java 1.3. The second edition was published in 2008 and includes new chapters about, among other things, generics, which were introduced in Java 1.5. Conveniently enough, the book's website has the chapter on generics as a free download. Since generics can be sort of tricky to get right I recommend reading that chapter (did I mention it's free?).

As a bonus, I now know what the heck these declarations

static <T extends Comparable<? super T>> void sort(List<T> list)
static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp)

(from Collections in the Java API) actually mean, and why they are the way they are. (See items 27 and 28 in the chapter on generics.)

No comments:

Post a Comment