Categories
Java Software Development

Items #1 & #2

If you are a Java Developer “Effective Java” by Joshua Bloch is the book you should read. It will help you become a better developer.

Every chapter of the book has several items. By following the advices of those items you will write higher quality idiomatic Java code. Also, if you study each item carefully you will not only learn best practices but also understand why many things that seem unnecessary, counterintuitive or obscure (especially when talking about concurrency and serialization) are the way they are or are done in such a way.

Let me share an anecdote that always comes to my mind when I talk about this book. Long ago I was working as a Software Architect and one day a Java Software Engineer in the team told to me “I don’t want to create factories or builders for my classes. I want to be agile”. Yes, he said that, word by word and he was a bit frustrated.

My first reaction was to question “why are static factory methods and builders getting in the way of your agility?

From his explanation I understood that he thought that writing static factory methods or builders was too much code, too much boilerplate, too much verbosity.

Of course there’s a lot truth in what he was trying to say! That’s why we have code generators like Lombok which has its builder annotation or IDEs that generate that code.

It’s worth noting that his frustration had nothing to do with our scrum-ish development process (apples and oranges) and it had everything to do with him not knowing why certain practices and patterns are in use in the Java community.

Where am I going with this? Here we have a guy that is actually able to write Java code, is familiar with a few practices and patterns because he has seen them around, he is even able to name them, but has no clue why, when or how to properly use them. He thinks they are a waste of time.

How did I explained him the reasons why we were doing the things we were doing? I gave him a quick summary of Effective Java items 1 and 2:

  • Item 1: “Consider static factory methods instead of constructors”
  • Item 2: “Consider a builder when faced with many constructor parameters

If this is new to you, I would suggest you to get the Kindle sample and read those items. You will learn the advantages and disadvantages of static factory methods and builders (and you will probably end up buying the book).

Back then I had read the second edition. I just went through the third edition almost completely (I skipped the Exceptions and Serialization chapters) At last I am effectively updated to Java 8 & 9!

This book is a fantastic source of knowledge. It is a book to revisit from time to time. Similar to what they did on this excellent podcast from the Android community called Fragmented I’m going to write down more about several items of this book that I like and find very useful in upcoming posts.

Now, go read the book and have fun coding more effectively!

Leave a Reply

Your email address will not be published. Required fields are marked *