About

I am a software developer in Seattle, building a new AI software company.

Ads

August 2009

Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          

Ads


« Joel Test | Main | Expression Trees »

November 23, 2005

Comments

Null member access, does that refer to:

MyObject obj = null;

obj.MyMethod(); // Won't throw a NullReferenceException as long it the method doesn't touch 'this'

Wesner Moise

Yes... I probably should have said null method invocation.

Wesner Moise

I suspect more Office documents will constructed outside of Office than inside Office.

Ayende Rahien

Why is null method invocation good for?

Wesner Moise

Null method invocation only works for nonvirtual calls. The C# team was forced to issue a callvirt instead of call instruction for non-virtual methods.

A major benefit of this is in performance from eliminating null checks before each instance method call.

Also, An instance method can treat an null in special, default way to maintain continuity with nonnull objects and eliminate the need for callers to perform null checks. One example of this is how it simplifies the manipulation of binary trees.

It's similar to the null object pattern, with the null object being null.

The comments to this entry are closed.