News for hackers. Stuff that matters.
Re:Java 8’s new Optional type doesn't solve anything by louthy on Monday October 26, 2015 @10:35AM (#10451696)
Whilst non-nullable references are useful, that isn't what Option is trying to solve. The problem with null references is that when you're handed a reference to an object of type T - the type system is saying to you: "This is the contract I will honour". Except it doesn't when the reference is null.

However the functionality of a null reference type is useful, because it allows a function to return 'no value'. So the goal of an Option type should be to expose the contract for T when there's a value and remove the contract when there's no-value.

The programmer is then explicitly forced to acknowledge the two states that the value could be.

Shameless plug - My C# implementation of Option which is possibly the most complete example out there (at least in C# world):

https://github.com/louthy/language-ext/blob/master/LanguageE...

There are no comments on this comment yet.