One thing I'm surprised he didn't mention is exception handling. Namely the growing acceptance that checked exceptions are dumb. I make a point that except for a few rare circumstanes, my code should never have a throws clause. I always created subclasses of RuntimeException (or Spring's NestedRuntimeException) and use them exclusively. Any libs that throw checked exceptions get either handled or rethrown with a custom RuntimeException.
Better Java – Resources for Writing Modern Java
11–20 of 192 posts
Re: Better Java – Resources for Writing Modern Java
#12Re: Better Java – Resources for Writing Modern Java
#13>> Good alternatives to using Spring is Google and Square's Dagger library or Google's Guice. They don't use Spring's XML configuration file format, and instead they put the injection logic in annotations and in code Spring has had code-based configurations since 2009[1]; seems a little disingenuous to recommend Guice/Dagger due to this non-existent limitation. [1] http://spring.io/blog/2009/12/22/configuration-simpl…
> It [the Spring framework] has a either code-based wiring or XML configuration-based wiring.
Re: Better Java – Resources for Writing Modern Java
#14The only way it seems you can be effective with Java is with an IDE to do most of the heavy lifting. What would be better is if Java shipped with more focused command-line tools and better defaults that allow me to productive immediately without the need to learn something as hefty as IntelliJ / Eclipse. This could lessen the barrier of entry to Java and widen community adoption.
Re: Better Java – Resources for Writing Modern Java
#15Re: Better Java – Resources for Writing Modern Java
#16Re: Better Java – Resources for Writing Modern Java
#17>> Good alternatives to using Spring is Google and Square's Dagger library or Google's Guice. They don't use Spring's XML configuration file format, and instead they put the injection logic in annotations and in code Spring has had code-based configurations since 2009[1]; seems a little disingenuous to recommend Guice/Dagger due to this non-existent limitation. [1] http://spring.io/blog/2009/12/22/configuration-simpl…
Not sure how you get that reading... the author makes no claim that Spring is limited to XML configuration. In fact, in the paragraph just before the one you quote: > It [the Spring framework] has a either code-based wiring or XML configuration-based wiring.
Re: Better Java – Resources for Writing Modern Java
#18The problem with the struct approach is that numerous tooling / libraries expects beans with typical getter/setters - Jackson Json, Spring binding, etc. Yes it's possible with configurations and/or annotations to get around this, but IMO, saving a few lines of code in exchange for non-default behavior isn't a valid trade-off.
Adding a dependency on Lombock is even worse.
Honestly, I can spot a Bean class within 1 second of opening it up. Unlike Scala or other languages, Java programmers typically use one class per file, and beans rarely get in the way as they're typically contained in some 'model' package anyway.
Re: Better Java – Resources for Writing Modern Java
#19Please don't use Java 8's default methods in interface's to do multiple inheritance, and code reuse. Prefering this over 'Util' classes is bad as it is inheritance over composition. The default methods were designed to facilitate easier interface migration
If you are unhappy with candy-shop utils class and are ready to split them into smaller entities, go the whole way there. Create proper small classes, and inject them using your chose DI technology.
Anyway, kudos to the author, that was a risky article to put together and there was no way to write it without controversial recommendations. That's a good start for what a new java developer need to look for.
Re: Better Java – Resources for Writing Modern Java
#20Use constructors. This makes perfectly testable classes and is vastly simpler than encouraging more XML as code. Any proper dependency injection framework should work quite well with regular constructors.