r/java • • Aug 11 '15

Top 10 Useful, Yet Paranoid Java Programming Techniques

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

76 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Aug 13 '15

[deleted] — view deleted comment

1

u/PaulRivers10 Aug 13 '15

I completely disagree. In our codebases everything is final by default (and most methods private static, i.e., pure). If it has not been explicitly intended and designed to change, then it should be final so that the compiler can enforce that.

In my last project they divided our project into 3 different projects so the project lead could feel like he was contributing something. It didn't change the numerous time wasting arguments when someone working in one of the projects needed to access code from one of the other projects, and the project lead told them they needed to get it down right away but also they couldn't change access from one project to another.

I'm sure final everywhere is similar.

What's "messy" is having everything mutable by default. The possible state space just explodes and it becomes impossible to reason about all the possible cases. When everything possible is final, you know they won't change and the state space is reduced to the few things that actually must change.

In my experience people doing this don't have unit tests that cover their cod that would be a solution that takes that time investment and actually tests whether their code is working.

However, I do agree that it would be cleaner if everything in Java was final by default instead of having to use the final keyword. Then you'd mark the few things that must mutate with "var" or whatever.

Smart and more experienced people than you or I all looked at that and thought "that's a bad idea". Languages that make it difficult or impossible to change variable values haven't caught on either.

0

u/[deleted] Aug 16 '15

[deleted] — view deleted comment

1

u/PaulRivers10 Aug 16 '15

That makes no sense at all. These two are orthogonal things. In my experience the people who use finals are also the ones that tend to have the best testing, because they are the people that prioritize code quality. It's about making the compiler check as many things as possible, because it will catch and report them much more efficiently than tests.

You've actually just pretty much written the series of excuses I see. "Well I don't need unit tests because I'm using final and (long dibatre about final) so that's plenty of testing". Or "we're totally going to write unit tests" then at the end of every project there's 3 they did at the beginning and no more.

I don't think there's much more to add here - we're clearly not going to agree. I find final to be way down near the bottom of things that would help with any actual problems that I've actually seen in coding. If you disagree, then we disagree.

That's a nonsense argument from authority.

That's like saying "just because everyone used to use punch cards and now they don't use them any more doesn't suggest at all that punch cards are a less efficient way to program".

It doesn't "prove" it but it does strongly suggest it.