Java: Optional.isPresent() is not the best usage of Optional

Using the Optional class from Guava or JDK8?

The TL;DR: If you’re using isPresent(), you’re not taking full advantage of Optional.

Optional allows one to explicitly state that a variable may not have a value rather than relying on comments/code convention and null values.

It provides a number of helpers for constructing Optional items. Optionals are basically a wrapper around an object, and can either be ‘absent’ or ‘present’.

Optional provides an ‘isPresent’ method, but if you’re using it, you aren’t taking full advantage of Optional. Using isPresent isn’t really any different than using {var} != null from a coding perspective.

The Guava Optional provides several methods for retrieving items. If you know it will always have a value (likely due to previous checks), you can use get().

If you’re not sure if it will have a value or not, and want the default returned to be null, use orNull(). There is also an or(defaultValue) that will return defaultValue if it isn’t defined and an or that will return a different Optional value.

The JDK8 version of this is more powerful, but this at least gets one started. Here’s a great post about the JDK8 Optional:

http://www.oracle.com/technetwork/articles/java/java8-optional-2175753.html

Groovy for Android Development

Apple recently announced the new programming language for iOS called Swift. One of the languages mentioned by Apple as providing inspiration was Groovy.

Here’s a presentation showing how to use Groovy for Android development. Looks a lot nicer than using Java for it. Take a look and see what you think. I’ll be investigating this for any Android development I have to do.

http://melix.github.io/blog/2014/06/grooid.html

Estimation: Story points or story counting?

A very interesting read about estimating and Story Points. Do they truly add value over just counting stories?

In the author’s experience, estimating and Story Points didn’t provide any additional information over counting stories.

There is value in the discussion around stories, and ensuring that stories aren’t too large, but discussing whether it’s a 1, 2, 3 or 5 doesn’t add huge value.

http://softwaredevelopmenttoday.blogspot.co.uk/2012/01/story-points-considered-harmful-or-why.html