Bug Vanquisher

29 October 2009

The World Of Bizarre and Eccentric Failures

Filed under: Tips — Tanveer Badar @ 12:21 PM

public IEnumerable<int> GetIntegers( )
    if( <some condition> )
        yield return null;
    yield return <some other value;

and the other beauty

public IList<int> Integers { get; set; }

Now befuddled when foreach fails with a NRE. Or when someone extra smart says Integers = null; But don’t blame the other guy who is using your code.

When returning a collection, it is expected that collection itself will never be null (short of OutOfMemoryException)) even when it is empty. Properties which return a collection interface should never have public setters.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

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 )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: