On Sunday, 19 May 2013 at 12:06:01 UTC, Simen Kjaeraas wrote:
My experience is the complete opposite - I think maybe 20% of
bugs at my job
are caused by null references. But as you say, they are very
easily fixed.
Sometime they are super freaking hard. I have a horror story
debugging Apache Cayenne : http://cayenne.apache.org/ because it
was throwing NPE on a race condition that would never show up
once the code is instrumented.
A reference was null for a short moment and then set to
something. Due to concurrency, in extreme cases it could be seen
as null where it was assumed everywhere to be set.
That said, two things to consider:
How many of the functions you write actually need to accept
nullable
pointers/references?
If non-nullable was the default, how often would you explicitly
ask for a
nullable pointer/reference?
Not that much and I'd rather be warned when it is the case.