r/java • • Mar 05 '18

Top 10 Useful, Yet Paranoid Java Programming Techniques

http://blog.jooq.org/2015/08/11/top-10-useful-yet-paranoid-java-programming-techniques/
223 Upvotes

105 comments sorted by

View all comments

52

u/AlainBienvenue Mar 05 '18

Like the author, as someone who has been coding in Java since 1999, I do not see anything wrong or even paranoid with any of these. Just good practices.

12

u/random314 Mar 05 '18

I don't enforce the always final rule, I've seen it done before but never really myself. Is it considered a very good practice? If so I might propose it to my team (we have a "good practice" checklist) in our next retro.

2

u/GhostBond Mar 07 '18

Is it considered a very good practice?

No.

It's just the latest fad from the same line of thinking which brought us:

  • Ruby on Rails is going to make Java obsolete!

  • Object/document databases are going to make sql databases obsolete!

  • Dynamic languages are going to make Java obsolete!

  • Groovy is going to make Java obsol...well you get the idea

Adding in the extra overhead - in typing, in reading through longer messier method signatures, in dealing with needing to change a value and not having it available - is particularly absurd in java where final just makes the reference immutable but not the object itself. Final makes "int index" immutable but "List indexes" is still a changeable list.

I don't think even in languages with better implementations it's worth it. Every decade someone rediscovers immutable-by-default. And languages that are not that way are the ones that get popular because they're a lot easier to use with a lot less frustrating overhead in writing code.

2

u/Zoerak Mar 07 '18 edited Mar 08 '18

Immutability is a nice property and should be preferred unless one has a good reason not to do so.

Scala does this right, the decision of mutability / non-mutability can be made without extra syntax noise in most scenarios.

In java, the final modifier on each variable bumps the visual noise. If the language was created today, a lot of things would be different.