Live data from Hacker News

New Year’s Resolutions for the Java Developer

blog.jelastic.com

11–18 of 18 posts

Re: New Year’s Resolutions for the Java Developer

#11

Java is a language for people good at resisting temptation. It gives you all sorts of ways to make your code look nicer, more elegant, but the only way to be productive in Java is to avoid all of them. In my experience, you can be more productive in Java than in any other language, because it has by the best tools and libraries. However, don't use reflection, don't use cloning, avoid automatic (de)serialization, don'…

More productive than any other language?

That's quite a bold claim...

I'd expect languages that require far less code for pretty much anything, and have far more compile-time safety to be more productive both at the prototyping stage, and at long term software maintenance.

Re: New Year’s Resolutions for the Java Developer

#12
post #11

Java is a language for people good at resisting temptation. It gives you all sorts of ways to make your code look nicer, more elegant, but the only way to be productive in Java is to avoid all of them. In my experience, you can be more productive in Java than in any other language, because it has by the best tools and libraries. However, don't use reflection, don't use cloning, avoid automatic (de)serialization, don'…

More productive than any other language? That's quite a bold claim... I'd expect languages that require far less code for pretty much anything, and have far more compile-time safety to be more productive both at the prototyping stage, and at long term software maintenance.

"In my experience"

It wasn't a broad claim, it was an observation.

Re: New Year’s Resolutions for the Java Developer

#13
I disagree with "Stop using Anonymous Inner classes and just bite the bullet and wait for 8." Are you going to stop development while you wait for 8 too?

Most IDEs tend to hide a little of the noise associated with anonymous inner classes and, at least, with IntelliJ, the auto-completion for things like Guava's Function are huge time savers that make it much more bearable.

Now, should you think twice before you reach for an anonymous inner class? Of course! But there are many situations in which "closures"/"functional-style" anonymous inner classes can significantly decrease the amount of code written and/or make it much clearer. Basically, it lets you stay D.R.Y. much better.

One very common situation is reusing a complicated data structure traversal, just to be able to do two different things with the same inner pieces of data. Without the ability to "pass in code" using anonymous inner classes, the way to avoid code duplication is to accumulate the final destination items in a list and return that from the traversal code, such that this intermediate list can then be fed into the two different code paths. Of course, often such a refactoring is not easy or litters the otherwise-clean traversal code with the details of the intermediate list population. If the intermediate list gets too long to fit into memory or if pagination is required, then you end up having to return an iterator of lists, etc. It just gets messy.

Contrast that with code that takes in an anonymous inner function to apply to each piece of data. Bam, it's so much simpler. Want to start paginating the traversal? No problem, the calling code is none the wiser.

Developers who've been using closures are very familiar with this style of coding. The ugly syntax of anonymous inner functions raises the bar for using them above many simpler situations, but the greater utility cannot be disputed.

Re: New Year’s Resolutions for the Java Developer

#14
post #7

I'm a Java advocate. Here's a few more: Learn YAGNI. Tattoo it on your friggen foreheads. Run lean... No, you DONT need to build a framework to complete your project! Stop abstracting god dang everything. Interfaces and composition are GOOD, use them. Inheritance and generalization use SPARINGLY, or not at all! Before you create an abstraction, are you CERTAIN sometime in the future you will swap the impl out or are…

My personal advice:

Writing a service? Use dropwizard[0]

Avoid EE6's version of CDI (WELD/OWB) and EE6 all together. Its slow and causes more problems than its worth. If you really want CDI, use gluice.

Guava is your friend.

Avoid JPA, specifically the parts regarding session management. Never liked it myself and Ebean[1] is a far cleaner ORM which reuses the JPA annotations for mapping classes.

Writing a user facing website? I don't have a good answer here honestly. JSF/EE6 is terrible, GWT - yuck, Wicket - yuck, in my opinion they all suck. For related options Grails seems ok, Play! seems ok, Rails on JRuby seems ok but I haven't used any of them enough to have any real opinion of them. We're currently using angular.js and Jersey for the API on the backend.

Groovy 2 is pretty awesome when performance isn't critical, use it.

[0] http://dropwizard.codahale.com/

[1] http://www.avaje.org/

Re: New Year’s Resolutions for the Java Developer

#15
post #14
post #7

I'm a Java advocate. Here's a few more: Learn YAGNI. Tattoo it on your friggen foreheads. Run lean... No, you DONT need to build a framework to complete your project! Stop abstracting god dang everything. Interfaces and composition are GOOD, use them. Inheritance and generalization use SPARINGLY, or not at all! Before you create an abstraction, are you CERTAIN sometime in the future you will swap the impl out or are…

My personal advice: Writing a service? Use dropwizard[0] Avoid EE6's version of CDI (WELD/OWB) and EE6 all together. Its slow and causes more problems than its worth. If you really want CDI, use gluice. Guava is your friend. Avoid JPA, specifically the parts regarding session management. Never liked it myself and Ebean[1] is a far cleaner ORM which reuses the JPA annotations for mapping classes. Writing a user facing…

Don't forget Joda Time (http://joda-time.sourceforge.net/), at least until Java 8 is out.

Re: New Year’s Resolutions for the Java Developer

#16
post #15
post #14

Earlier quoted context omitted.

My personal advice: Writing a service? Use dropwizard[0] Avoid EE6's version of CDI (WELD/OWB) and EE6 all together. Its slow and causes more problems than its worth. If you really want CDI, use gluice. Guava is your friend. Avoid JPA, specifically the parts regarding session management. Never liked it myself and Ebean[1] is a far cleaner ORM which reuses the JPA annotations for mapping classes. Writing a user facing…

Don't forget Joda Time ( http://joda-time.sourceforge.net/ ), at least until Java 8 is out.

Yes, Joda-Time is awesome and a default include is pretty much all of my POMs. I'd also add that if your dealing with monetary fields / calculations, Joda-Money is also a great way to avoid common pitfalls.

Re: New Year’s Resolutions for the Java Developer

#17
post #16
post #15

Earlier quoted context omitted.

Don't forget Joda Time ( http://joda-time.sourceforge.net/ ), at least until Java 8 is out.

Yes, Joda-Time is awesome and a default include is pretty much all of my POMs. I'd also add that if your dealing with monetary fields / calculations, Joda-Money is also a great way to avoid common pitfalls.

Tanks for pointing out Joda Money, didn?t know that one yet.

Re: New Year’s Resolutions for the Java Developer

#18
post #14
post #7

I'm a Java advocate. Here's a few more: Learn YAGNI. Tattoo it on your friggen foreheads. Run lean... No, you DONT need to build a framework to complete your project! Stop abstracting god dang everything. Interfaces and composition are GOOD, use them. Inheritance and generalization use SPARINGLY, or not at all! Before you create an abstraction, are you CERTAIN sometime in the future you will swap the impl out or are…

My personal advice: Writing a service? Use dropwizard[0] Avoid EE6's version of CDI (WELD/OWB) and EE6 all together. Its slow and causes more problems than its worth. If you really want CDI, use gluice. Guava is your friend. Avoid JPA, specifically the parts regarding session management. Never liked it myself and Ebean[1] is a far cleaner ORM which reuses the JPA annotations for mapping classes. Writing a user facing…

Yah I should have mentioned Guice, I just did my first project with it. It still enables a boat load of stupidity, but at least it doesn't have the cruft that comes with EE6.
Post reply on HN