Tuesday, January 15, 2008

The best java book?

Epiphanies are rarer as one gets older. Maybe its because we are less receptive to new thinking; maybe its because we have already learn most of what we need in our day-to-day lives. Whatever be it, the a-ha moments are few and far between. Its not all bad news though - the few that we have are that much more powerful.

I've been a programmer for the last eight years professionally and a lot longer as a hobbyist. My shelf of technical books is more or less empty. This is for two reasons - I outgrew some of the books and the others were not worth more than one read. Google and various tech forums are the resources I look to for any information I need and I guess its the same for most of my peers.

I came across a slim book called "Effective Java" by Joshua Bloch. My expectations were reasonably high since this is the highest rated Java book on javalobby.com. I expected intermediate to advanced concepts, tips, etc. This book offers all of those, but doing so is not its focus.

What this book is really about is good programming practices, sensible design, weighing options on performance, designing for reusability and longevity and so much more. In a book with a scant two hundred something pages, there is no place for slack. Each chapter is split into a set of principles or points. Each principle is illustrated with code. The writing is crisp, the examples clear. It hardly matters that the book was written years ago and the language has evolved. I am reading and rereading points here and will do so till they are internalized.

Take this list of tips on exception handling as an example.

  • Use exceptions only for exceptional conditions
  • Use checked exceptions for recoverable conditions and run-time exceptions for programming errors
  • Avoid unnecessary use of checked exceptions
  • Favor the use of standard exceptions
  • Throw exceptions appropriate to the abstraction
  • Document all exceptions thrown by each method
  • Include failure-capture information in detail messages
  • Strive for failure atomicity
  • Don't ignore exceptions

Simple? Arguably. Commonsense? Yes. Obvious? I wish!

The whole book is written in this vein. If someone had taught me all this when I had started out, I'd have saved years of learning the hard way.

No comments: