Thoughts from the office by Ed Ball
Wednesday, October 19, 2005

I read Effective Java, by Joshua Bloch, not because I ever write Java code (I don’t), but because it surprisingly was recommended as a valuable book for C# programmers. Sure enough, this book has excellent advice for programmers of any Java-like object-oriented framework. My favorites:

  • Item 1: Consider providing static factory methods instead of constructors
  • Item 6: Avoid finalizers
  • Item 12: Minimize the accessibility of classes and members
  • Item 13: Favor immutability
  • Item 14: Favor composition over inheritance
  • Item 15: Design and document for inheritance or else prohibit it
  • Item 27: Return zero-length arrays, not nulls
  • Item 29: Minimize the scope of local variables
  • Item 30: Know and use the libraries
  • Item 39: Use exceptions only for exceptional conditions
  • Item 46: Strive for failure atomicity

One item that caught my attention was item 16 (“Prefer interfaces to abstract classes”), because it directly conflicts with Cwalina and Abrams’ Framework Design Guidelines (“Do use abstract classes instead of interfaces to decouple the contract from implementations”). Of course, both books are expressing a general preference, not a strict rule, and both books identify the situations where each construct is appropriate.

Some of the items are particular to Java, but they were still interesting as education on some of the differences between Java and C#. I just skimmed the last chapter (“Serialization”), which basically discourages the use of Java’s serialization mechanism anyway. Furthermore, I don’t know how it compares to .NET serialization.

All in all, it was definitely worth reading, and I highly recommend it to seasoned C# programmers.

10/19/2005 4:10:02 PM (Pacific Daylight Time, UTC-07:00) | Comments [0] | Books#
Search
Archive
Links
Categories
Administration
Blogroll