<?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: The Null Coalescing Operator (Or how to make Default values sound frightening)</title>
	<atom:link href="http://kushalm.com/the-null-coalescing-operator-or-how-to-make-default-values-sound-frightening/feed" rel="self" type="application/rss+xml" />
	<link>http://kushalm.com/the-null-coalescing-operator-or-how-to-make-default-values-sound-frightening</link>
	<description></description>
	<lastBuildDate>Fri, 19 Aug 2011 17:24:40 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: kushal</title>
		<link>http://kushalm.com/the-null-coalescing-operator-or-how-to-make-default-values-sound-frightening/comment-page-1#comment-12</link>
		<dc:creator>kushal</dc:creator>
		<pubDate>Thu, 28 Jun 2007 22:41:37 +0000</pubDate>
		<guid isPermaLink="false">http://kushalm.com/the-null-coalescing-operator-or-how-to-make-default-values-sound-frightening#comment-12</guid>
		<description>It actually &lt;I&gt;does&lt;/I&gt; support value types. You only have to use &lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/1t3y8s4s(VS.80).aspx&quot; rel=&quot;nofollow&quot;&gt;Nullable&lt;/a&gt; Types (just add a question mark at the end and they are nullable).
As for handling null values in a database, I would have suggested you use &lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.data.sqltypes.aspx&quot; rel=&quot;nofollow&quot;&gt;System.Data.SQLTypes&lt;/a&gt;, but MS seems to &lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/ms172138.aspx&quot; rel=&quot;nofollow&quot;&gt;suggest&lt;/a&gt; that we use the &lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.data.sqltypes.inullable.isnull.aspx&quot; rel=&quot;nofollow&quot;&gt;IsNull&lt;/a&gt; property of the &lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.data.sqltypes.inullable.isnull.aspx&quot; rel=&quot;nofollow&quot;&gt;INullable&lt;/a&gt; interface instead. (all the SQLTypes implement it)</description>
		<content:encoded><![CDATA[<p>It actually <i>does</i> support value types. You only have to use <a href="http://msdn2.microsoft.com/en-us/library/1t3y8s4s(VS.80).aspx" rel="nofollow">Nullable</a> Types (just add a question mark at the end and they are nullable).<br />
As for handling null values in a database, I would have suggested you use <a href="http://msdn2.microsoft.com/en-us/library/system.data.sqltypes.aspx" rel="nofollow">System.Data.SQLTypes</a>, but MS seems to <a href="http://msdn2.microsoft.com/en-us/library/ms172138.aspx" rel="nofollow">suggest</a> that we use the <a href="http://msdn2.microsoft.com/en-us/library/system.data.sqltypes.inullable.isnull.aspx" rel="nofollow">IsNull</a> property of the <a href="http://msdn2.microsoft.com/en-us/library/system.data.sqltypes.inullable.isnull.aspx" rel="nofollow">INullable</a> interface instead. (all the SQLTypes implement it)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan Allen</title>
		<link>http://kushalm.com/the-null-coalescing-operator-or-how-to-make-default-values-sound-frightening/comment-page-1#comment-11</link>
		<dc:creator>Jonathan Allen</dc:creator>
		<pubDate>Wed, 20 Jun 2007 08:30:19 +0000</pubDate>
		<guid isPermaLink="false">http://kushalm.com/the-null-coalescing-operator-or-how-to-make-default-values-sound-frightening#comment-11</guid>
		<description>Completely useless for me. The only time this would be helpful for me is when I&#039;m cleaning database nulls but it doesn&#039;t support them nor does it support value types.</description>
		<content:encoded><![CDATA[<p>Completely useless for me. The only time this would be helpful for me is when I&#8217;m cleaning database nulls but it doesn&#8217;t support them nor does it support value types.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kushal</title>
		<link>http://kushalm.com/the-null-coalescing-operator-or-how-to-make-default-values-sound-frightening/comment-page-1#comment-10</link>
		<dc:creator>kushal</dc:creator>
		<pubDate>Tue, 19 Jun 2007 12:42:15 +0000</pubDate>
		<guid isPermaLink="false">http://kushalm.com/the-null-coalescing-operator-or-how-to-make-default-values-sound-frightening#comment-10</guid>
		<description>Glad that struck a chord Tim :)</description>
		<content:encoded><![CDATA[<p>Glad that struck a chord Tim <img src='http://kushalm.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kushal</title>
		<link>http://kushalm.com/the-null-coalescing-operator-or-how-to-make-default-values-sound-frightening/comment-page-1#comment-9</link>
		<dc:creator>kushal</dc:creator>
		<pubDate>Tue, 19 Jun 2007 12:02:40 +0000</pubDate>
		<guid isPermaLink="false">http://kushalm.com/the-null-coalescing-operator-or-how-to-make-default-values-sound-frightening#comment-9</guid>
		<description>Hi Matt,
Yes that feature might come in useful alright. Although I think there may be a little more it. For example

&lt;pre lang=&quot;csharp&quot;&gt;
myString = myObject.myValue 
         [?? or some other GuardOperator Here] &quot;Default Value&quot;;
&lt;/pre&gt;

... is straight forward enough. But what if someone were to write this:

&lt;pre lang=&quot;csharp&quot;&gt;
myString = myObject.mySubObject.myValue 
           [GuardOperator Here] &quot;Default Value&quot;;
&lt;/pre&gt;

Now should the compiler set the default value only if &lt;span class=&quot;km_code&quot;&gt;mySubObject&lt;/span&gt; is null? (and throw an exception if &lt;span class=&quot;km_code&quot;&gt;myObject&lt;/span&gt; is null). Or should it guard against the entire expression altogether? 

Because it isn&#039;t really useful if doesn’t guard against the entire expression, I guess what you&#039;re really asking for is a shortcut for catching &lt;span class=&quot;km_code&quot;&gt;NullReferenceExcption&lt;/span&gt;s as opposed to a shortcut for an &lt;span class=&quot;km_code&quot;&gt;if-else&lt;/span&gt; clause. Something like this:
&lt;pre lang=&quot;csharp&quot;&gt;
string myString;
try
{
	myString = myObject.mySubObject1.mySubObject2.Value;
}
catch(NullReferenceException e)
{
	myString = &quot;Default Value&quot;;
}
&lt;/pre&gt;

... and I agree that would indeed be useful. (The Javascript guard operator is a little odd because it can return either myValue or myObject.)
Its a pity one can&#039;t really write a method for doing this. (In C# that is) You can use reflection but then you&#039;d lose the strong typing.</description>
		<content:encoded><![CDATA[<p>Hi Matt,<br />
Yes that feature might come in useful alright. Although I think there may be a little more it. For example</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">myString <span style="color: #008000;">=</span> myObject.<span style="color: #0000FF;">myValue</span> 
         <span style="color: #000000;">&#91;</span><span style="color: #008000;">??</span> or some other GuardOperator Here<span style="color: #000000;">&#93;</span> <span style="color: #666666;">&quot;Default Value&quot;</span><span style="color: #008000;">;</span></pre></div></div>

<p>&#8230; is straight forward enough. But what if someone were to write this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">myString <span style="color: #008000;">=</span> myObject.<span style="color: #0000FF;">mySubObject</span>.<span style="color: #0000FF;">myValue</span> 
           <span style="color: #000000;">&#91;</span>GuardOperator Here<span style="color: #000000;">&#93;</span> <span style="color: #666666;">&quot;Default Value&quot;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Now should the compiler set the default value only if <span class="km_code">mySubObject</span> is null? (and throw an exception if <span class="km_code">myObject</span> is null). Or should it guard against the entire expression altogether? </p>
<p>Because it isn&#8217;t really useful if doesn’t guard against the entire expression, I guess what you&#8217;re really asking for is a shortcut for catching <span class="km_code">NullReferenceExcption</span>s as opposed to a shortcut for an <span class="km_code">if-else</span> clause. Something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">string</span> myString<span style="color: #008000;">;</span>
<span style="color: #0600FF;">try</span>
<span style="color: #000000;">&#123;</span>
	myString <span style="color: #008000;">=</span> myObject.<span style="color: #0000FF;">mySubObject1</span>.<span style="color: #0000FF;">mySubObject2</span>.<span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">catch</span><span style="color: #000000;">&#40;</span>NullReferenceException e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	myString <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Default Value&quot;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>&#8230; and I agree that would indeed be useful. (The Javascript guard operator is a little odd because it can return either myValue or myObject.)<br />
Its a pity one can&#8217;t really write a method for doing this. (In C# that is) You can use reflection but then you&#8217;d lose the strong typing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: From the &#8220;Couldn&#8217;t have said it better myself&#8221; department &#171; Tim.GetInstance( )</title>
		<link>http://kushalm.com/the-null-coalescing-operator-or-how-to-make-default-values-sound-frightening/comment-page-1#comment-8</link>
		<dc:creator>From the &#8220;Couldn&#8217;t have said it better myself&#8221; department &#171; Tim.GetInstance( )</dc:creator>
		<pubDate>Mon, 18 Jun 2007 18:25:25 +0000</pubDate>
		<guid isPermaLink="false">http://kushalm.com/the-null-coalescing-operator-or-how-to-make-default-values-sound-frightening#comment-8</guid>
		<description>[...] From the &#8220;Couldn&#8217;t have said it better myself&#8221;&#160;department  &#8220;Javascript often strikes me as the Ferris Bueller of programming languages. Not always taken seriously, but still surprisingly inventive and most of all - very, very annoying.&#8221; -kushal [...]</description>
		<content:encoded><![CDATA[<p>[...] From the &#8220;Couldn&#8217;t have said it better myself&#8221;&nbsp;department  &#8220;Javascript often strikes me as the Ferris Bueller of programming languages. Not always taken seriously, but still surprisingly inventive and most of all &#8211; very, very annoying.&#8221; -kushal [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://kushalm.com/the-null-coalescing-operator-or-how-to-make-default-values-sound-frightening/comment-page-1#comment-7</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Mon, 18 Jun 2007 18:03:41 +0000</pubDate>
		<guid isPermaLink="false">http://kushalm.com/the-null-coalescing-operator-or-how-to-make-default-values-sound-frightening#comment-7</guid>
		<description>I honestly find this operator rarely useful. I typically want something like this:

string myString = myObject.Value ?? &quot;default value&quot;;

as in, I want whatever Value is, as long as myObject is not null, otherwise the default value. Which obviously ?? does not accomplish, but I just find this scenario comes up more often.

have to stick with the old standby...
string myString = myObject == null ? &quot;default value&quot; : myObject.Value;</description>
		<content:encoded><![CDATA[<p>I honestly find this operator rarely useful. I typically want something like this:</p>
<p>string myString = myObject.Value ?? &#8220;default value&#8221;;</p>
<p>as in, I want whatever Value is, as long as myObject is not null, otherwise the default value. Which obviously ?? does not accomplish, but I just find this scenario comes up more often.</p>
<p>have to stick with the old standby&#8230;<br />
string myString = myObject == null ? &#8220;default value&#8221; : myObject.Value;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

