-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decide if we will ever return null from a function. #10
Comments
I prefer to never return nulls, so either 2 or 3 fits that criteria. But in my opinion,
I suggest never return Does this mixed strategy works for you? |
I'm nearly in agreement with @magicDGS, but not quite. My view is that |
So from the comments here, what I imagine now as a safe design:
Some return methods can distinguish in the API between missing in the record and missing value defined (e.g., VCF I found this Wiki page from guava quite good for this discussion too: https://github.com/google/guava/wiki/UsingAndAvoidingNullExplained |
More info about |
What's about Bean Validation for specifying this and other constraints? |
How do we feel about returning
nulls
? It's gross, but I'm not totally convinced that optionals are actually less gross in java. Optional has the benefit of documenting the fact that something may not be present wherenull
can be a surprise. The have the downside that it's wrapping the element in a new object which is potentially expensive for critical things.I think we have 3 options:
getX
methods. This has the advantage of avoiding NPE but is similarly error prone if people forget to check thehasX
. It could also be complicated to efficiently implementhasX
ifgetX
is something other than returning a field.The text was updated successfully, but these errors were encountered: