karamelchef / karamel

Reproducing Distributed Systems and Experiments on Cloud
http://www.karamel.io
Apache License 2.0
39 stars 22 forks source link

Replace null checks with Optional #73

Closed alorlea closed 9 years ago

alorlea commented 9 years ago

I have seen around the code that we do null checks and usually it leads to very bad antipatterns making later the code difficult to fix bugs due to null.

One nice way to get rid of this is by using Google's Guava Optional or Java 8 Optional leading to better and clearer code.

https://www.voxxed.com/blog/2015/05/why-even-use-java-8-optional/

I recommend, we try to use it in our code and even will give better maintainability. We can try to include it with new code.

jimdowling commented 9 years ago

I don't know if we want to require java 8. This is a desktop application, and the vast majority of people don't have java 8, but do have java 7. Java 7+ is a requirement right now. But Google's Guava optional sounds like a good idea. Do you fancy adding this in your branch?

alorlea commented 9 years ago

I understand, still we should try to have in mind a transition when we can to Java 8 as Oracle dropped support on that platform on april this year http://www.oracle.com/technetwork/java/eol-135779.html

I will try add Guava optional in my current branch.

kamalhakim commented 9 years ago

Yes, we should use Guava more.. I will add a developers guide part in the Readme, there we can enumerate those preferred practices for everyone.