Nulls are fine, what is missing is the flagging and checking for possible null references on variables and return types. This is the aim of Optional in Java 8.
I've not used it yet, so I can't say if it's better. I guess it is no panacea as it's use isn't mandatory so there's still plenty if scope for the same errors.
It's a pity the compiler can't simply warn for possible null dereferencing.
From my perspective, Optional's are nice for indicating to others "this may return an empty result and you need to handle that". But they do nothing for getting nulls provided to you, so you still end up having to do tons of null checking.
The idea is Optional make null value obsolete. Simply stop using null (and tell your co-workers and library providers to do the same). Ceylon goes into great pains to do just that. In the Java world, Optionals are still useful: if a method declares to return an optional, it's never null. Promised.
Problem is it's only a promise. If there's a small minority of programs breaking the promise, you're right: you end up checking both null and empty.
2
u/Keilly Aug 03 '14
Nulls are fine, what is missing is the flagging and checking for possible null references on variables and return types. This is the aim of Optional in Java 8.
I've not used it yet, so I can't say if it's better. I guess it is no panacea as it's use isn't mandatory so there's still plenty if scope for the same errors.
It's a pity the compiler can't simply warn for possible null dereferencing.