Chimera wishlist : !NullReferenceException

What features from other languages do you wish your main development language had?

As someone whose first real applications were written in C++, the thing that always bugged me about C# and Java (after they got generics and autoboxing sorted) was the way they handled references. In my C++ mind, C# and Java pass pointers around, and pointers are allowed to be null. So every single time I have to use them, I have to check them for null, or set up the caller to make sure they’re not null. As Anders Hejlsberg points out, that single fact causes more problems than anything else in C#.

Also, I wish C# allowed const references like C++ to guarantee an object isn’t modified within a method when passing by reference, which is always useful to avoid copying large objects. C# would have to support const methods too, of course.

50% of the bugs that people run into today, coding with C# in our platform, and the same is true of Java for that matter, are probably null reference exceptions. If we had had a stronger type system that would allow you to say that ‘this parameter may never be null, and you compiler please check that at every call, by doing static analysis of the code’. Then we could have stamped out classes of bugs.

But peppering that on after the fact once you’ve built a whole platform where this isn’t built in… it’s very hard to pepper on afterwards. Because if you start strengthening your APIs and saying that you can’t pass null here or null here or null here, then all of a sudden you’re starting to break a bunch of code. It may not be possible for the compiler to track it all properly.

Anyway, those are just things that are tough later. You sort of end up going, well ok, if we ever get another chance in umpteen years to build a new platform, we’ll definitely get this one right. Of course then we’ll go and make other mistakes! But we won’t make that one.

http://www.computerworld.com.au/index.php/id;1149786074;pp;3

So, what do you wish for?

Advertisements

One thought on “Chimera wishlist : !NullReferenceException

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s