Live data from Hacker News

An Opinionated Guide to Modern Java Development, Part 1

blog.paralleluniverse.co

251–260 of 402 posts

Re: An Opinionated Guide to Modern Java Development, Part 1

#251

I'd like to hear thoughts on CheckedExceptions in part 2. IMO, they are a disaster - most projects degrade into all methods having a "throws Exception" clause. But I'm not sure if there is any consensus on how the CheckedException haters like myself work around them. I use Runtime exceptions everywhere, but it's a pain/boilerplate to convert them.

I think some of the additions in Java7/8 will make them a little easier to work with. The worst thing used to be the necessity to nest multiple try/catch blocks, or repeat identical code between separate catch blocks because different components throw different errors. This is now dramatically helped by the multi-catch and other additions.

Like you, I use a lot of RuntimeExceptions, but I think in it's important not to overlook the benefit of checked exceptions: if you're trying to write reliable software looking up and understanding every possible failure mode of every API you are calling is an almost unbearably tedious and impossibly boring task. In principle, having the compiler check and tell you "Hey, there's this error that could occur and you haven't defined how your code is dealing with that" is a tremendously useful thing. Our human tendency to focus only on the successful path through our code and then ignore all the possible failures is terrible bias if you're trying to make code that behaves the right way under ANY circumstance. So I support checked exceptions, and I hope the new improvements in Java make them more workable and accepted. There probably need to be more improvements, something long the lines of STM type features before we'll get there though, I think.

Re: An Opinionated Guide to Modern Java Development, Part 1

#252
post #207

Earlier quoted context omitted.

> Maven also suffers from XML hell, but at least it has dependency management. I don't find it that bad. The nice thing about it is how my IDE will auto complete almost everything and it should be possible to validate it without even using an IDE, as it has a schema. I agree with your complaints about Ant. The thing I was hoping gradle would give me is the ability to write tests for my build. EG: I want to have more…

w/ regards to gradle using groovy.... in gradle I can easily add in variables to my dependencies, I can write conditionals (if System Prop X then include dependency Y). Basically anything you can do in code, you can do in gradle very easily. Auto-complete does work in IntelliJ 13 - at least for groovy code type stuff. Nothing for the gradle DSL (that could be implemented of course). > Java devs do many things manuall…

> I can write conditionals (if System Prop X then include dependency Y).

I stand corrected. That would be extremely useful. Maven is really awkard about these things. EG: "I want to run integration tests but not unit tests". Here's how: http://stackoverflow.com/questions/6612344/prevent-unit-test... Pretty lame.

Re: An Opinionated Guide to Modern Java Development, Part 1

#253
post #202
post #6

I'm back to java after having an unsatisfying experience 2 years ago with Spring MVC, (this time i use the "play framework"), and it seems to confirm my intuition that the language itself is really just fine. The problem lies more in bloated frameworks and corporate culture where everything needs to be standardized, regulated, and the purpose of a mandatory non-free training session. Add to that the fact that every s…

I was just recently trying to decide between "new" Spring MVC, Dropwizard, and Play. Spring now has a bunch of slick-looking guides and tutorials. But then I looked at the actual contents of their tutorial project, and it just turned me off. For an "example" REST project, they had over 50 classes not including tests: https://github.com/spring-guides/tut-rest/tree/master/6/comp... , with many being "event" classes of…

I'm using Dropwizard for the same reason. It is dead simple and gets me going out of the box. You should also give Grails a try if you plan on having a view layer

Re: An Opinionated Guide to Modern Java Development, Part 1

#254

Earlier quoted context omitted.

that's absurd. 1) I can't embed code in XML. 2) Why should I use a format that takes 5x as much space to declare something as a more usable format?

Agreed. On top of which XML has no capacity for logic, barring an incredibly contrived construct.

What kinds of logic are you putting in your builds? That's a sign you are doing things wrong.

Re: An Opinionated Guide to Modern Java Development, Part 1

#256
post #202
post #6

I'm back to java after having an unsatisfying experience 2 years ago with Spring MVC, (this time i use the "play framework"), and it seems to confirm my intuition that the language itself is really just fine. The problem lies more in bloated frameworks and corporate culture where everything needs to be standardized, regulated, and the purpose of a mandatory non-free training session. Add to that the fact that every s…

I was just recently trying to decide between "new" Spring MVC, Dropwizard, and Play. Spring now has a bunch of slick-looking guides and tutorials. But then I looked at the actual contents of their tutorial project, and it just turned me off. For an "example" REST project, they had over 50 classes not including tests: https://github.com/spring-guides/tut-rest/tree/master/6/comp... , with many being "event" classes of…

Been there done that. 3.5 years of Play 1, but they decided to rewrite it in Scala and I left in anger.

Nearly one year now of servlet dev, trying nearly anything I can get my hands on. Most I have been satisfied with is Restlet for service development, otherwise nothing even comes close to Play 1.

Finally decided to harden up and learn Scala. I have set my prejudices aside and after a month, I can safely say I am a _write_only_ Scala developer. I still can't read much of the fancy code in the wild, but for my immediate needs, gluing java libraries together, it's a far superior language to Java.

My opinionated guide to developing modern Java is: get TypeSafe Activator and learn Scala.

Re: An Opinionated Guide to Modern Java Development, Part 1

#258
post #43
post #39

Not a single mention of Guice or even dependency injection? Seems like a gaping omission in a guide that claims to be about "modern" Java.

Dependency injection has seen its day. The gains promised by DI/IoC containers tend to be outweighed by the complexity they introduce. I'm looking at you, Spring.

DI is fine, it's just the way people overuse it that's an abomination. I general inject the most significant pieces, or the pieces that are changed. I won't even introduce DI unless I know I'm going to setup a different config of it. My coworkers (sigh), insist that nearly everything must be injected to "eliminate dependencies". (and because it makes it "easier to test"). YMMV

Re: An Opinionated Guide to Modern Java Development, Part 1

#259

Earlier quoted context omitted.

I agree. Hibernate has become a downright liability at times in our codebase. These days I only use it in new code for query parameterization and result row transforms into models. Speaking of which, if anyone knows of a good library for query parameterization alone, let me know...

JDBI is quite good: http://jdbi.org/

A second shoutout for JDBI. I don't attempt to use it for anything fancy, but it hides a lot of the JDBI boilerplate in a very sane way.

Re: An Opinionated Guide to Modern Java Development, Part 1

#260

Earlier quoted context omitted.

Not quite. eg: public final Date date; date.setTime(1); That's not immutable.

Yep, the thing is that Date is immutable. I think that this public final immutable rule is ok, but one has to ensure the fields themself are really not modifiable.

The Java Date class is not immutable.
Post reply on HN