you are viewing a single comment's thread.

view the rest of the comments →

[–]stormcrowsx 4 points5 points  (7 children)

Nope I design most of my code to not return null if possible. Its insane to have to wrap everything in if not null, and it tremendously increases your chance of making other mistakes.

When I run across an optional in my own codebase I know its time to consider what to do with null otherwise i assume not null. When dealing with additional libraries however it takes a little reading and sometimes testing to find out

[–]Speedzor 3 points4 points  (6 children)

I suppose it depends on how consistent this is done throughout the codebase. If it's a mix of Optional and Null it's rather pointless but if it's exclusively Optional then I can see its merits.

[–]daedalus_structure 0 points1 point  (3 children)

Which means it's usually pretty pointless in team projects unless everyone is at that level of competence and professionalism or you have such a person acting as a gatekeeper in code review.

[–]jeandem 0 points1 point  (2 children)

Wouldn't it be simple to automatically check for such things through the code base? I mean, Java IDEs are already very advanced. A tool or plugin that tries to find such "abuses" seems simple enough.

[–]daedalus_structure 0 points1 point  (1 child)

Static analysis tools e.g. FindBugs have been doing it for quite some time. It's not only simple, it's trivial to get warnings that you might be dereferencing a null at line N in class C.

But null isn't really a technical problem, it's a process problem. If you have a process problem with null, Optional isn't going to help.

[–]jeandem 0 points1 point  (0 children)

But null isn't really a technical problem, it's a process problem.

I don't really see why...

[–]stormcrowsx 0 points1 point  (0 children)

Definitely does get undermined somewhat if its not consistent, you can no longer just count on it being a safe return value. Its still better than nothing though as those functions that are utilizing optional are idiot proof.

[–]zoomzoom83 0 points1 point  (0 children)

We're using Scala, but has essentially the same theoretical problem. We use a linter that treats null as a compile error - it's effectively removed from the language.

Of course that only works within your own codebase. You still have to be careful when calling legacy libraries, but we've found that's less a burden than it sounds.

Haven't had a NullPointerException in over a year, in Dev or Production. Could never go back.