Comments on: Java, Ten Years Later http://www.danvk.org/wp/2011-11-05/java-ten-years-later/ Keepin' static like wool fabric since 2006 Wed, 08 Oct 2014 14:33:23 +0000 hourly 1 http://wordpress.org/?v=3.9.2 By: Kenny Leftin http://www.danvk.org/wp/2011-11-05/java-ten-years-later/comment-page-1/#comment-118974 Fri, 18 Nov 2011 06:46:34 +0000 http://www.danvk.org/wp/?p=765#comment-118974 If you’re doing a lot more with Java, it’s worth reading Effective Java by Josh Bloch. It’s the bible for good Java idioms. (There’s a free pdf copy within Google that you can read)

Be careful with your last point. static {} is convenient for a project with only a couple classes, but it can get un-maintainable really quickly. Since the static block is executed only when the class is loaded, it can be surprising when it will or will not run. The ‘static’ keyword in Java in general can be a little hairy. See Puzzle 5 (http://www.javapuzzlers.com/java-puzzlers-sampler.pdf) for class initialization craziness. Not to mention, it’s almost impossible to mock any sort of static method in a unit test. I basically only use static for two things:

1. Defining final constants
2. Writing methods that need absolutely no state

What are you working on nowadays that uses Java? You should e-mail me!

]]>
By: danvk http://www.danvk.org/wp/2011-11-05/java-ten-years-later/comment-page-1/#comment-117399 Mon, 07 Nov 2011 15:40:32 +0000 http://www.danvk.org/wp/?p=765#comment-117399 There’s something nearly identical to Java’s foreach in C++11: http://en.wikipedia.org/wiki/C%2B%2B11#Range-based_for-loop

Unfortunately, we’re not allowed to use either that or boost::foreach at work yet :(

]]>
By: Craig Fratrik http://www.danvk.org/wp/2011-11-05/java-ten-years-later/comment-page-1/#comment-117333 Mon, 07 Nov 2011 06:43:47 +0000 http://www.danvk.org/wp/?p=765#comment-117333 Boost Foreach is pretty good.

]]>