<?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/"
		>
<channel>
	<title>Comments on: Returning &#8216;null&#8217; Considered Dishonest</title>
	<atom:link href="http://andypalmer.com/2008/08/returning-null-considered-dishonest/feed/" rel="self" type="application/rss+xml" />
	<link>http://andypalmer.com/2008/08/returning-null-considered-dishonest/</link>
	<description>Views on software, technology, consulting and business process</description>
	<lastBuildDate>Fri, 18 Nov 2011 07:13:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Returning Nulls is Dishonest &#124; Ramblings of a wanna be developer</title>
		<link>http://andypalmer.com/2008/08/returning-null-considered-dishonest/comment-page-1/#comment-1089</link>
		<dc:creator>Returning Nulls is Dishonest &#124; Ramblings of a wanna be developer</dc:creator>
		<pubDate>Thu, 03 Feb 2011 01:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.andypalmer.com/blog/?p=9#comment-1089</guid>
		<description>[...] The post is here: http://andypalmer.com/2008/08/returning-null-considered-dishonest/ [...]</description>
		<content:encoded><![CDATA[<p>[...] The post is here: <a href="http://andypalmer.com/2008/08/returning-null-considered-dishonest/" rel="nofollow">http://andypalmer.com/2008/08/returning-null-considered-dishonest/</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy Palmer &#187; Installing Eclipse</title>
		<link>http://andypalmer.com/2008/08/returning-null-considered-dishonest/comment-page-1/#comment-127</link>
		<dc:creator>Andy Palmer &#187; Installing Eclipse</dc:creator>
		<pubDate>Sun, 22 Feb 2009 22:26:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.andypalmer.com/blog/?p=9#comment-127</guid>
		<description>[...] empty (apart from the comment) method for void types, or return null;. I&#8217;ve already discussed my thoughts on returning null, and I would rather my code failed if it hits an unimplemented method rather than continue in a [...]</description>
		<content:encoded><![CDATA[<p>[...] empty (apart from the comment) method for void types, or return null;. I&#8217;ve already discussed my thoughts on returning null, and I would rather my code failed if it hits an unimplemented method rather than continue in a [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamal Mavadat</title>
		<link>http://andypalmer.com/2008/08/returning-null-considered-dishonest/comment-page-1/#comment-23</link>
		<dc:creator>Jamal Mavadat</dc:creator>
		<pubDate>Mon, 08 Sep 2008 14:35:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.andypalmer.com/blog/?p=9#comment-23</guid>
		<description>Try-get pattern is supposed to add a hybrid support!!! A solution to another problem...</description>
		<content:encoded><![CDATA[<p>Try-get pattern is supposed to add a hybrid support!!! A solution to another problem&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fredrik</title>
		<link>http://andypalmer.com/2008/08/returning-null-considered-dishonest/comment-page-1/#comment-22</link>
		<dc:creator>Fredrik</dc:creator>
		<pubDate>Mon, 08 Sep 2008 08:04:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.andypalmer.com/blog/?p=9#comment-22</guid>
		<description>Calling Drink() when the vending machine has not yet received enough money would be an invalid operation for the current state of the vending machine - so f.ex throwing an InvalidOperationException would be OK here, imo. &lt;br/&gt;&lt;br/&gt;If you don&#039;t want an exception, you could use TryGet pattern:&lt;br/&gt;&lt;br/&gt;Drink drink;&lt;br/&gt;if(vendingMachine.TryGetDrink(out drink))&lt;br/&gt;{&lt;br/&gt;   // we got a drink!&lt;br/&gt;}</description>
		<content:encoded><![CDATA[<p>Calling Drink() when the vending machine has not yet received enough money would be an invalid operation for the current state of the vending machine &#8211; so f.ex throwing an InvalidOperationException would be OK here, imo. </p>
<p>If you don&#8217;t want an exception, you could use TryGet pattern:</p>
<p>Drink drink;<br />if(vendingMachine.TryGetDrink(out drink))<br />{<br />   // we got a drink!<br />}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamal Mavadat</title>
		<link>http://andypalmer.com/2008/08/returning-null-considered-dishonest/comment-page-1/#comment-20</link>
		<dc:creator>Jamal Mavadat</dc:creator>
		<pubDate>Fri, 15 Aug 2008 12:51:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.andypalmer.com/blog/?p=9#comment-20</guid>
		<description>@Andy, you&#039;re most welcome matey, my pleasure for being here :)&lt;br/&gt;&lt;br/&gt;Andy said: &lt;i&gt;&quot;I want my code to fail fast. If I don&#039;t get a Drink, I want my code to tell me why.&quot;&lt;/i&gt; As said before, both approaches can co-exist, and now you described a situation in which you shouldn&#039;t be using null-refs! Perhaps solutions such as response-types (normal flow with additional info), or exceptions (exception or error flow optionally with yet more info).&lt;br/&gt;&lt;br/&gt;Examples for returning nulls (sure we have alternatives):&lt;br/&gt;1- getDefaultDrinkOrNull( ) if no-default-drink is considered a typical response and we prefer handling it in normal flow, fortunately designer has cleared all potential confusion by proper naming.&lt;br/&gt;2- in a linked-list I may like getNext( ) return next object or &lt;b&gt;null&lt;/b&gt; for the trail gifting more simplicity for iterations.&lt;br/&gt;&lt;br/&gt;I think the &quot;drink&quot; example is a bit too generic! We could better be discussing null issues by real-world scenarios. For example:&lt;br/&gt;A- If the Drink type is actually a Customer in a web scenario then returning response-types or exceptions are probably better approaches.&lt;br/&gt;B- In a getTempFile( ) : File I might go for exceptions if it cannot return a temp file!&lt;br/&gt;C- And for getActiveUser in a security service I might prefer returning null for indicating no-active-user message - however, I myself have designed security services in which active users were returned by response-types and some specific exceptions too. My mind wasn&#039;t changed, they were just proper solutions for their unique requirements.&lt;br/&gt;&lt;br/&gt;All I try to say is, we should NOT replace null-handling, BUT we may discuss a particular case in which null-handling is not the best.</description>
		<content:encoded><![CDATA[<p>@Andy, you&#8217;re most welcome matey, my pleasure for being here <img src='http://andypalmer.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Andy said: <i>&#8220;I want my code to fail fast. If I don&#8217;t get a Drink, I want my code to tell me why.&#8221;</i> As said before, both approaches can co-exist, and now you described a situation in which you shouldn&#8217;t be using null-refs! Perhaps solutions such as response-types (normal flow with additional info), or exceptions (exception or error flow optionally with yet more info).</p>
<p>Examples for returning nulls (sure we have alternatives):<br />1- getDefaultDrinkOrNull( ) if no-default-drink is considered a typical response and we prefer handling it in normal flow, fortunately designer has cleared all potential confusion by proper naming.<br />2- in a linked-list I may like getNext( ) return next object or <b>null</b> for the trail gifting more simplicity for iterations.</p>
<p>I think the &#8220;drink&#8221; example is a bit too generic! We could better be discussing null issues by real-world scenarios. For example:<br />A- If the Drink type is actually a Customer in a web scenario then returning response-types or exceptions are probably better approaches.<br />B- In a getTempFile( ) : File I might go for exceptions if it cannot return a temp file!<br />C- And for getActiveUser in a security service I might prefer returning null for indicating no-active-user message &#8211; however, I myself have designed security services in which active users were returned by response-types and some specific exceptions too. My mind wasn&#8217;t changed, they were just proper solutions for their unique requirements.</p>
<p>All I try to say is, we should NOT replace null-handling, BUT we may discuss a particular case in which null-handling is not the best.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://andypalmer.com/2008/08/returning-null-considered-dishonest/comment-page-1/#comment-19</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Thu, 14 Aug 2008 20:00:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.andypalmer.com/blog/?p=9#comment-19</guid>
		<description>@Jamal, thanks for commenting.&lt;br/&gt;I want my code to fail fast. If I don&#039;t get a Drink, I want my code to tell me why.&lt;br/&gt;I don&#039;t want my client code, that is expecting to receive a Drink, to have to check that I didn&#039;t cheat him and give him a null instead :-)&lt;br/&gt;Can you give me an example of when a null is a valid response to something that is expecting a Drink object? That is, can you describe a situation where an object that needs a Drink to work with, would be happy with a null?</description>
		<content:encoded><![CDATA[<p>@Jamal, thanks for commenting.<br />I want my code to fail fast. If I don&#8217;t get a Drink, I want my code to tell me why.<br />I don&#8217;t want my client code, that is expecting to receive a Drink, to have to check that I didn&#8217;t cheat him and give him a null instead <img src='http://andypalmer.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> <br />Can you give me an example of when a null is a valid response to something that is expecting a Drink object? That is, can you describe a situation where an object that needs a Drink to work with, would be happy with a null?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamal Mavadat</title>
		<link>http://andypalmer.com/2008/08/returning-null-considered-dishonest/comment-page-1/#comment-18</link>
		<dc:creator>Jamal Mavadat</dc:creator>
		<pubDate>Thu, 14 Aug 2008 19:22:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.andypalmer.com/blog/?p=9#comment-18</guid>
		<description>@Andy&lt;br/&gt;IMO classic programmers are usually implementing C-Style control flows! Programming languages with exception support however add more convenience and support to the case, BUT do not replace null-reference handling. Here we go (I know this isn&#039;t the perfect example):&lt;br/&gt;if(( machine = getActiveMachine()) == null) { ... }&lt;br/&gt;else if(( drink = getMeADrink() == null) { ... } ...&lt;br/&gt;In the above example we don&#039;t expect something &quot;exceptional&quot; and everything is checked sequentially branching should a particular condition triggers - this is supposed to be the normal flow.&lt;br/&gt;&lt;br/&gt;BUT exceptions are beautiful if it&#039;s really considered an &quot;exception&quot; and should pick an alternate flow instead of the regular normal flow. For instance, designer of openFile( ) method MIGHT decide to throw an exception if invalid filename supplied!&lt;br/&gt;&lt;br/&gt;Good design employs a mixture of both types; the point is to properly decide what should be considered the &quot;normal&quot; flow and what should be the &quot;exception&quot; or &quot;error&quot; flow! The rest is THE ART OF DESIGN... in summary I stand for proper use of null-handling and exception-flows, not eliminating any of them...</description>
		<content:encoded><![CDATA[<p>@Andy<br />IMO classic programmers are usually implementing C-Style control flows! Programming languages with exception support however add more convenience and support to the case, BUT do not replace null-reference handling. Here we go (I know this isn&#8217;t the perfect example):<br />if(( machine = getActiveMachine()) == null) { &#8230; }<br />else if(( drink = getMeADrink() == null) { &#8230; } &#8230;<br />In the above example we don&#8217;t expect something &#8220;exceptional&#8221; and everything is checked sequentially branching should a particular condition triggers &#8211; this is supposed to be the normal flow.</p>
<p>BUT exceptions are beautiful if it&#8217;s really considered an &#8220;exception&#8221; and should pick an alternate flow instead of the regular normal flow. For instance, designer of openFile( ) method MIGHT decide to throw an exception if invalid filename supplied!</p>
<p>Good design employs a mixture of both types; the point is to properly decide what should be considered the &#8220;normal&#8221; flow and what should be the &#8220;exception&#8221; or &#8220;error&#8221; flow! The rest is THE ART OF DESIGN&#8230; in summary I stand for proper use of null-handling and exception-flows, not eliminating any of them&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://andypalmer.com/2008/08/returning-null-considered-dishonest/comment-page-1/#comment-16</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Mon, 11 Aug 2008 15:55:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.andypalmer.com/blog/?p=9#comment-16</guid>
		<description>This post is making me thirsty!</description>
		<content:encoded><![CDATA[<p>This post is making me thirsty!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kris</title>
		<link>http://andypalmer.com/2008/08/returning-null-considered-dishonest/comment-page-1/#comment-15</link>
		<dc:creator>Kris</dc:creator>
		<pubDate>Mon, 11 Aug 2008 12:32:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.andypalmer.com/blog/?p=9#comment-15</guid>
		<description>@Andy&lt;br/&gt;&lt;br/&gt;The blinkNotEnoughMoneyLight() would live in the vending machine. I use it to bring up the point of how the code is intended to react to being able to give out a drink - blinking a light to the user indicating more money is needed.&lt;br/&gt;&lt;br/&gt;There is no contract that there should always be a drink from a vending machine. There is probably a business rule that says that once the needed money has been given. The value of null would only given out when that precondition is violated, which would only happen from programmer error.</description>
		<content:encoded><![CDATA[<p>@Andy</p>
<p>The blinkNotEnoughMoneyLight() would live in the vending machine. I use it to bring up the point of how the code is intended to react to being able to give out a drink &#8211; blinking a light to the user indicating more money is needed.</p>
<p>There is no contract that there should always be a drink from a vending machine. There is probably a business rule that says that once the needed money has been given. The value of null would only given out when that precondition is violated, which would only happen from programmer error.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ben.biddington</title>
		<link>http://andypalmer.com/2008/08/returning-null-considered-dishonest/comment-page-1/#comment-14</link>
		<dc:creator>ben.biddington</dc:creator>
		<pubDate>Mon, 11 Aug 2008 09:36:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.andypalmer.com/blog/?p=9#comment-14</guid>
		<description>And provided are informed how to avoid NotEnoughMoneyException, then they need not use try/catch as control flow.</description>
		<content:encoded><![CDATA[<p>And provided are informed how to avoid NotEnoughMoneyException, then they need not use try/catch as control flow.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

