<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
	>
<channel>
	<title>Comments on: Never return Null Arrays &#8211; really?</title>
	<atom:link href="http://blog.punchbarrel.com/2008/10/16/never-return-null-arrays-really/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.punchbarrel.com/2008/10/16/never-return-null-arrays-really/</link>
	<description>Frank Carver&#039;s musings about software and life</description>
	<lastBuildDate>Sun, 22 Jan 2012 22:15:12 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Frank</title>
		<link>http://blog.punchbarrel.com/2008/10/16/never-return-null-arrays-really/comment-page-1/#comment-712</link>
		<dc:creator>Frank</dc:creator>
		<pubDate>Fri, 17 Oct 2008 18:48:29 +0000</pubDate>
		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=681#comment-712</guid>
		<description>In general, I agree. In many (most?) situations &quot;no box&quot; and &quot;empty box&quot; should be treated as the same thing, but surely you can also imagine situations where they should be dealt with differently?

Perhaps it helps to start by considering some simpler objects before we get to collections. Is a null Integer always the same as 0? If so, what char is the same as a null Character?

It is a fairly popular idiom that null means &quot;not supplied&quot; or &quot;not available&quot;, and informs the code that an application-specific default or some calculated value should be used instead. A null Integer might &quot;mean&quot; 0, 1, MAX_VALUE, the current time, etc. depending on the context or program state, so passing around a null to indicate this seems reasonable to me.

The same idiom also seems reasonable for arrays and collections. A null means &quot;not supplied&quot; or &quot;not available&quot;, and client code is free to interpret that as appropriate. This interpretation may be as an empty array or collection, but also may be as some context-dependent default set of data.

As for the plate example, it was mainly a bit of fun, but the point still stands. In the real world the absence of a container and the presence of an empty container are completely different, and many business processes rely on that difference.

Your &quot;hasPaid = true&quot; example might be equivalent to giving each customer a receipt and requiring them to show that receipt every time they go over to the buffet. While there are no doubt some places which work this way, the restaurant business has largely accepted that this is a less efficient way to work. It requires a person (a.k.a. extra code) at the buffet to examine this receipt each time, slows down the buffet line (performance problems), can suffer from lost or unreadable receipts (bugs/exceptions) etc.</description>
		<content:encoded><![CDATA[<p>In general, I agree. In many (most?) situations &#8220;no box&#8221; and &#8220;empty box&#8221; should be treated as the same thing, but surely you can also imagine situations where they should be dealt with differently?</p>
<p>Perhaps it helps to start by considering some simpler objects before we get to collections. Is a null Integer always the same as 0? If so, what char is the same as a null Character?</p>
<p>It is a fairly popular idiom that null means &#8220;not supplied&#8221; or &#8220;not available&#8221;, and informs the code that an application-specific default or some calculated value should be used instead. A null Integer might &#8220;mean&#8221; 0, 1, MAX_VALUE, the current time, etc. depending on the context or program state, so passing around a null to indicate this seems reasonable to me.</p>
<p>The same idiom also seems reasonable for arrays and collections. A null means &#8220;not supplied&#8221; or &#8220;not available&#8221;, and client code is free to interpret that as appropriate. This interpretation may be as an empty array or collection, but also may be as some context-dependent default set of data.</p>
<p>As for the plate example, it was mainly a bit of fun, but the point still stands. In the real world the absence of a container and the presence of an empty container are completely different, and many business processes rely on that difference.</p>
<p>Your &#8220;hasPaid = true&#8221; example might be equivalent to giving each customer a receipt and requiring them to show that receipt every time they go over to the buffet. While there are no doubt some places which work this way, the restaurant business has largely accepted that this is a less efficient way to work. It requires a person (a.k.a. extra code) at the buffet to examine this receipt each time, slows down the buffet line (performance problems), can suffer from lost or unreadable receipts (bugs/exceptions) etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott Selikoff</title>
		<link>http://blog.punchbarrel.com/2008/10/16/never-return-null-arrays-really/comment-page-1/#comment-708</link>
		<dc:creator>Scott Selikoff</dc:creator>
		<pubDate>Fri, 17 Oct 2008 17:09:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=681#comment-708</guid>
		<description>I consider Examples 1 and 2 the same.  Functionally they serve the same purpose:  to indicate the person has not provided any &#039;stuff&#039;.  The syntax is different, but logically there shouldn&#039;t be.

The problem here is that you&#039;re letting (plate == null) serve a dual, possibly ambiguous purpose.  In this manner, your mixing the data about whether or not the person has paid and data about what the user is holding, which are contextually very different things.  If the person has paid, there should be a boolean flag to indicate that such as &quot;hasPaid = true&quot;.</description>
		<content:encoded><![CDATA[<p>I consider Examples 1 and 2 the same.  Functionally they serve the same purpose:  to indicate the person has not provided any &#8216;stuff&#8217;.  The syntax is different, but logically there shouldn&#8217;t be.</p>
<p>The problem here is that you&#8217;re letting (plate == null) serve a dual, possibly ambiguous purpose.  In this manner, your mixing the data about whether or not the person has paid and data about what the user is holding, which are contextually very different things.  If the person has paid, there should be a boolean flag to indicate that such as &#8220;hasPaid = true&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeanne</title>
		<link>http://blog.punchbarrel.com/2008/10/16/never-return-null-arrays-really/comment-page-1/#comment-707</link>
		<dc:creator>Jeanne</dc:creator>
		<pubDate>Fri, 17 Oct 2008 15:33:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=681#comment-707</guid>
		<description>I completely agree that the Null Object pattern should only be used when it makes sense.  I think the distinction Scott is making is that a list/array is a &quot;special&quot; type of object.  In particular, a list of zero objects has meaning.  If I do a query and get no objects back, an empty list semantically fits.  Just like an empty ResultSet.  Whereas if I query by primary key, it opens the debate of whether a null of null object is better.

-Jeanne</description>
		<content:encoded><![CDATA[<p>I completely agree that the Null Object pattern should only be used when it makes sense.  I think the distinction Scott is making is that a list/array is a &#8220;special&#8221; type of object.  In particular, a list of zero objects has meaning.  If I do a query and get no objects back, an empty list semantically fits.  Just like an empty ResultSet.  Whereas if I query by primary key, it opens the debate of whether a null of null object is better.</p>
<p>-Jeanne</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.535 seconds -->

