HN Books @HNBooksMonth

The best books of Hacker News.

Hacker News Comments on
Effective Java (2nd Edition)

Joshua Bloch · 10 HN comments
HN Books has aggregated all Hacker News stories and comments that mention "Effective Java (2nd Edition)" by Joshua Bloch.
View on Amazon [↗]
HN Books may receive an affiliate commission when you make purchases on sites after clicking through links on this page.
Amazon Summary
Are you looking for a deeper understanding of the Java™ programming language so that you can write code that is clearer, more correct, more robust, and more reusable? Look no further! Effective Java™, Second Edition, brings together seventy-eight indispensable programmer’s rules of thumb: working, best-practice solutions for the programming challenges you encounter every day. This highly anticipated new edition of the classic, Jolt Award-winning work has been thoroughly updated to cover Java SE 5 and Java SE 6 features introduced since the first edition. Bloch explores new design patterns and language idioms, showing you how to make the most of features ranging from generics to enums, annotations to autoboxing. Each chapter in the book consists of several “items” presented in the form of a short, standalone essay that provides specific advice, insight into Java platform subtleties, and outstanding code examples. The comprehensive descriptions and explanations for each item illuminate what to do, what not to do, and why. Highlights include: New coverage of generics, enums, annotations, autoboxing, the for-each loop, varargs, concurrency utilities, and much more Updated techniques and best practices on classic topics, including objects, classes, libraries, methods, and serialization How to avoid the traps and pitfalls of commonly misunderstood subtleties of the language Focus on the language and its most fundamental libraries: java.lang, java.util, and, to a lesser extent, java.util.concurrent and java.io Simply put, Effective Java™, Second Edition, presents the most practical, authoritative guidelines available for writing efficient, well-designed programs.
HN Books Rankings

Hacker News Stories and Comments

All the comments and stories posted to Hacker News that reference this book.
Effective Java, while a bit out of date is still relevant https://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/03...
Effective Java http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/032...
organsnyder
I found Effective Java to be very enlightening—not just for Java, but for any language. It's especially at providing patterns for writing APIs with a guide toward future maintainability.
sanderjd
I'm going through that right now, and finding it incredibly good, but still fairly outdated. It was written for Java 6, while Java 7 and (especially) 8 have more or less re-written the language. All of the advice is still really great, but some of the items are workarounds for weaknesses in the language that have since been strengthened. I'm working through Java 8 in Action[0] in parallel, and it's been a good experience.

I've also been enjoying this Modern Java blog series, which is book-ish[1].

In a similar vein, I really enjoyed Effective Modern C++[2].

I think The Ruby Way[3] is still the best ruby book, and a new edition just came out earlier this year.

I'm looking for a good book about modern javascript if anyone has any suggestions.

[0]: https://www.goodreads.com/book/show/20534354-java-8-in-actio...

[1]: http://blog.paralleluniverse.co/2014/05/01/modern-java/

[2]: https://www.goodreads.com/book/show/22800553-effective-moder...

[3]: https://www.goodreads.com/book/show/4514.The_Ruby_Way

davedx
> I'm looking for a good book about modern javascript if anyone has any suggestions.

I just finished writing an eBook about building large modern web apps in JavaScript. If you're interested, here's the link:

https://leanpub.com/buildingbattletestedfrontendsoftware

Cheers!

Yes. I believe such a book exists (or should at least) for every language as well.

Effective Java — http://www.amazon.com/Effective-Java-Edition-Joshua-Bloch/dp...

POODR (Ruby) — http://www.poodr.com/

Javascript the good parts — http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockfor...

There is of course also the gang of 4 language agnostic classic on design patterns http://www.amazon.com/Design-Patterns-Elements-Reusable-Obje...

May 30, 2014 · saryant on Java 8 Features
Already been written, though not updated for Java 8:

http://www.amazon.com/Effective-Java-Edition-Joshua-Bloch/dp...

Not true. You'll get, for instance, people who read Effective Java [1], by Joshua Bloch (who is, IMHO, THE man when it comes to java), and remembered the PECS mnemonics. PECS stands for producer-extends, consumer-super.

So, to cite the textbook example, say you are implementing a Stack<E>. It will probably have the methods:

  public void push(E element);
  public E pop();
and, for convenience:

  public void pushAll(Iterable<? extends E> elements);
  public void popAll(Collection<? super E> destination);
The pushAll has "? extends" because the elements Iterable will "produce" elements for the stack. The popAll has super because the destination Collection will "consume" elements from the stack. It is not that hard, is it? Let's note that guard-of-terra is talking about proficiency, not mere familiarity. I believe reading "Effective Java" is a nice way to get closer to the proficient level.

Let it be noted that this whole mess exists because generics in Java were implemented with type erasure so their introduction wouldn't break legacy code. I personally think this was a bad idea, but it does show that when a language is evolving, there are a bunch of constraints the designers must be aware of.

[1] http://www.amazon.com/Effective-Java-Edition-Joshua-Bloch/dp...

ootachi
This doesn't seem to have anything to do with type erasure, does it? It's needed for type-safe generics. Even without type erasure, you still need type safety. If your generics are always covariant (like Dart's are), you break type safety.

I think the mistake the Java designers made here was going with use-site variance instead of definition-site variance.

reginaldo
Yes, you're right. We're talking about variance when it comes to the "? extends, ? super" situation, not erasure. And you're also right the things would be better with definition-site variance.

On the other hand, sometimes I think an unsound type system with List<String> being a subtype of List<Object> would be better than what we have today, for pragmatic reasons. Of course, I think this makes me a non-type-theorist, as what I'm saying is considered heresy in some circles [1].

[1] http://lambda-the-ultimate.org/node/4377 (search for unsound).

guard-of-terra
But than you can never get anything from List<String>! Because you never know what type are you getting!

On the other hand, if your structure is immutable it would probably work.

I am passionate about writing good code, and I'll try to offer some practical advice. As others said, the first step is understanding the importance of writing clean code and taking pride in your craft. By doing this, you are already ahead of most other programmers who don't really care. Now, how do you improve?

1) Read books.

With 4-5 years of experience, you already have a good intuition for "good" and "bad" code. Still, it doesn't hurt to learn more about it. There are a lot of good books on this subject.

The first is "Clean Code", by Robert C. Martin. It's the first book I read on this subject, and I learned a lot. Note that the book uses Java in the examples, but I think the ideas would apply to most other languages.

Its author, Uncle Bob ( http://en.wikipedia.org/wiki/Robert_Cecil_Martin ) has long been a proponent of writing clean, beautiful code. He recently did an interview for Xebia: http://blog.xebia.fr/2011/05/25/interview-avec-robert-martin... (French blog, but the interview is in English). In it, he advises:

"Well there are a number of books that talk about writing code well. Kent Beck wrote a book called “Implementation Patterns” very recently. It’s an excellent book all about software craftsmanship. The pragmatic programmers wrote a wonderful book in 2000 called “The pragmatic programmer”, again a wonderful book. Chad Fowler wrote a book call the “Passionate Programmer”. Again the book is about doing everything well. I wrote a book recently called “Clean Code” which is very specific about particular things you can do with your code to do it well. So there is a tremendous number of resources that are available for people who are interested in doing software craftsmanship well."

Out of those, disregard "The passionate Programmer". It's an okay book, but its focus is on building a good programmer career, not on code.

"Implementation Patterns" by Kent Beck is a great book with a lot of best practices when writing * Java * code. Less useful if you use another language.

"The pragmatic programmer" is a good book on software craftsmanship. I'm personally half-way through. There is a lot of good advice in it, but I often find myself thinking it's "common-sense". Maybe because I've already been exposed to most of the ideas by reading blogs? Still, it's a great book, with a lot of best practices. It's main focus is not code, though, so you might want to start with other books if your focus is on writing good code.

To these books, I'd add "Code Complete (2nd Edition)" (language-agnostic) and "Effective Java 2nd Edition" if you use Java.

Summary:

If you use Java, read:

  - Clean Code - http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882
  - Effective Java 2nd Edition - http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683
  - Implementation Patterns - http://www.amazon.com/Implementation-Patterns-Kent-Beck/dp/0321413091
  - Code Complete / Pragmatic Programmer
If you use another language, read:

  - Clean Code - http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882
  - Code Complete - http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670
  - Pragmatic Programmer - http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X
Other people might chime in with suggestions for other languages?

2) Practice.

Implement what you learned in the books. Keep improving.

3) Read other people's code.

Read good open source code. Not all code is good code. Ask around for OSS projects with good code in your language.

If you use Java, start with:

  - Google Guava - http://code.google.com/p/guava-libraries/
  - Google Guice - http://code.google.com/p/google-guice/
  - Spring Framework - http://www.springsource.org/
4) Practice.

5) Practice.

kevintaylor
I believe it is important to also have a view and strategy for your career. Read "Apprenticeship Patterns."

I highly recommend the other books, too.

Cheers, Kevin

mabid
Thank you so much for the comprehensive reply. You are right when you say that with 4-5 years of experience I know to some extent what good and bad code is. but sometimes I think a lot and write the best code that i can, and later after some time i realize; by looking at some one else's code or by myself knowing a new feature of the language i am using, that i could have done it in a much better way .. that is much more beautiful. My problem is that if my code doesnt look like poetry to me, clean readable understandable i feel the need to improve it.
I don't know how relevant it is for mobile development but I'd recommend Effective Java by Joshua Bloch (http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/032...). It's essentially the equivalent of Effective C++ for Java and it does a good job of explaining how to properly use the language. It also contains quite a few general programming advises which are applicable to other languages. Just keep in mind that it assumes that you already know the language and have a bit of experience under your belt.
Assuming you know the basics of the language, Effective Java by Joshua Bloch is very good: http://www.amazon.com/gp/product/0321356683/
Effective Java (2nd Edition) by Joshua Bloch: http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/032...

It's not for beginner Java programmers, but if you have experience in other similar programming languages you may get away with it.

rbxbx
Awesome, there's a copy of this on the bookshelf at work.

Will report back with it's friendliness(or lack there of) to beginning Java devs.

None
None
fogus
I'm not sure I would agree. "Effective Java" is a great Java book and absolutely recommended reading to know more Java. However, many of the tips provided are meant to address Java-specific foibles -- most, if not all, are addressed by using Clojure in the first place.
acangiano
You are probably right. I guess the OP is trying to learn more about the Java ecosystem, rather than simply the language per se. In that sense, your comment about Maven and Classpath is most likely spot on.
Jun 18, 2008 · pbnaidu on Ask YC: Best book for Java
I would also read Effective Java along with Struts related text book. Here's the link to the book http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/032...
HN Books is an independent project and is not operated by Y Combinator or Amazon.com.
~ yaj@
;laksdfhjdhksalkfj more things
yahnd.com ~ Privacy Policy ~
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.