On Jun 24, 2:57 pm, "kevin bourrillion" <
kev...@google.com> wrote:
> I'd like to get some opinions from the list on whether using nulls as values
> in a map feels more like a 90% use case to you, or a 50 or a 10 or what.
I'd say maybe a 30% to 50% case -- depends a lot on the particular use
of the map. There are lots of scenarios where I'd want to avoid using
nulls in a map, and equally lots of scenarios where having null values
in a map would be useful.
It's certainly true that many projects have data structures that may
contain nulls (database records, POJOs with object references). Null
handling can be a problem in Java applications, and over-use of null
values can be a 'code smell'. It's interesting to consider options
like Nice's null-handling (
http://nice.sourceforge.net/safety.html)
and other approaches in languages yet to come. There are alternatives
even in Java like the 'null object' pattern, but ultimately I often
find that judicious use of null is simpler than the alternatives. I'm
open to the idea that may be a failing on my part, but for the moment,
I'll note that I'd be surprised to find that many projects eliminate
uses of null in their objects altogether.
An implementation of Map that restricts my choices and/or forces me to
consider making refactorings which will certainly cost time (even if
they may be beneficial in other respects) is probably an
implementation I'll end up using less often. (Which doesn't mean that
invalidates the idea of a null-value-free collection, just means I
won't use it as often as I might otherwise).
> I'm more concerned with sacrificing the ideal behavior that non-nullable use
> cases want to have; treatment of null as a first class citizen is known to
> be fraught with peril and an anti-pattern, and I don't mind our library
> being one more way in which dealing with nulls is a little more annoying
> than not. I'm ok with users feeling some motivation to find other, more
> null-less approaches to their code.
Although I sympathize, I wonder how often you'll find that users feel
motivation to find other, more null-friendly approaches to Map. ;)
- Geoffrey