r/programming • • 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/
28 Upvotes

35 comments sorted by

View all comments

5

u/robby_w_g Aug 11 '15 edited Feb 15 '26

Lorem ipsum dolor sit amet consectetur adipiscing elit. Quisque faucibus ex sapien vitae pellentesque sem placerat. In id cursus mi pretium tellus duis convallis. Tempus leo eu aenean sed diam urna tempor. Pulvinar vivamus fringilla lacus nec metus bibendum egestas. Iaculis massa nisl malesuada lacinia integer nunc posuere. Ut hendrerit semper vel class aptent taciti sociosqu. Ad litora torquent per conubia nostra inceptos himenaeos.

3

u/valenterry Aug 11 '15

You can also return null values randomly and throw errors randomly from your library. How is it your fault if the callers program breaks? He could have caught the nulls and the errors.

But if you want to write software that does not break so easy, you should better make everything final and thus not use inheritance at all. Also never return null. It helps everyone who uses your code.

Though, Java is a language that can make it quite hard to do those things, because e.g. there is no help for delegating all method calls to an internal object. So not using inheritance means you have to implement all the methods of the interface of the object you want to delegate to yourself. That's kinda annoying, so it might be an excuse still to use inheritance. However it's not an execuse for using Java at all!

1

u/pakoito Aug 12 '15

Also never return null.

I try to abide by this, but what do you do for cases where it's difficult to find an alternative, i.e. convert string to enum by equals.

Optional is Java8, we're working on Java6 still.

1

u/valenterry Aug 13 '15

As I said, if your language puts a spoke in your wheel, change that first. In Java 6 you can still create your own Option type (there are also already defined types you can use (e.g. in Google Guava) but they are of course not as comfortable without lambdas. =/