Proposal: Elvis and Other Null-Safe Operators (original) (raw)

Jeremy Manson jeremy.manson at gmail.com
Tue Mar 3 11:36:51 PST 2009


On Tue, Mar 3, 2009 at 11:31 AM, Jeremy Manson <jeremy.manson at gmail.com> wrote:

Flipping through a few thousand lines' worth of our source files, I see hundreds of examples of #1, and only a couple of examples of #2. Most of the time, we know a priori that we're not doing a null dereference, so we don't need the ?..  This pretty much gels with my intuition about this.  Perhaps it is different in EE code?  I would be interested to hear a more thorough study of people's source bases.  If it is true that #2 is only responsible for a tiny fraction of the cases in general, then it is a little odd to add a programming language feature around it.

I should add to this that most of the cases I found were things like:

if (foo != null) { foo.bar(); }

That's not really all that compelling. The really compelling case for this feature is:

foo.bar().goo().baz().bif();

where each and everyone needs to be null checked, and you want to abandon the computation if any is null. I didn't see any of these at all, but, as I said, this might be different in EE code.

Jeremy



More information about the coin-dev mailing list