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

Show parent comments

15

u/[deleted] Mar 05 '18

It's not that it happens often, but in the last 6 months I've had to override 2x final methods in Spring and OpenSAML. In each case, making the method final was a PITA. IIRC, I C/P the whole class (I had other edits) in the OpenSAML situation and used reflection to fuck shit up in the Spring situation.

I completely understand why those methods were final. But it was an error in the logic within those methods that caused me (the actual programmer responsible for the feature working) to have to mess around with a library author who thought they knew best.

9/10, they're right. Hell, 99/100, they're right - but there's always those situations where they're not. That's why I don't like final for methods specifically.

2

u/lukaseder Mar 06 '18

The value of final far outweighs your pain. You could have just patched the library in those 2 cases, which you admitted were rare. It would have resulted in the same workaround, and you would have hoped for the library to ship an actual fix just the same.

It's like SQL. These days, we need to tune maybe 1 / 1000 SQL queries and because we're so used to having such excellent optimisers, we're completely surprised by those really rare cases. But yet, our own bias and lack of intuitive understanding of statistics leads to us outweighing the very rare painful occasions compared to the frequent experience of quality.

In other words: You're obviously exaggerating.

3

u/[deleted] Mar 06 '18

That's the thing - I have something to do for my job. Shipping something as a fix (which I do 3/4 of the time) to the upstream version isn't going to help me now.

So, in that sense, no - it does not outweigh my pain. Keeping a method final doesn't help me at all. You're trying to tell me "hey, I'm going to give you access to less stuff and you are going to be better off" to which I can't agree, fundamentally. Sure, if I'm a shitty dev I might break stuff - to which I argue: let the shitty devs break stuff. They're going to do it anyway, why hide behind a language construct which restricts usage for everyone.

My great hate for final is really focused around methods and classes. I goes right up there with protected methods for things that are useful as public methods (I'm looking at you JSCH!)

2

u/GhostBond Mar 07 '18

Yeah, same here. I'm not sure in web dev if I've ever seen a bug that would actually been prevented by final/const. I've had deal with a few huge headaches when someone in old code didn't let you set things you needed to set.