<?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: .NET Nullable Types and DBNull Expose Design Flaws</title>
	<atom:link href="http://www.zorched.net/2005/11/17/net-nullable-types-and-dbnull-expose-design-flaws/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zorched.net/2005/11/17/net-nullable-types-and-dbnull-expose-design-flaws/</link>
	<description>Musings of a software developer in Milwaukee, WI.</description>
	<pubDate>Tue, 06 Jan 2009 01:01:14 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: hfrmobile</title>
		<link>http://www.zorched.net/2005/11/17/net-nullable-types-and-dbnull-expose-design-flaws/comment-page-1/#comment-14362</link>
		<dc:creator>hfrmobile</dc:creator>
		<pubDate>Fri, 19 Dec 2008 09:07:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/?p=12#comment-14362</guid>
		<description>You're right, the DBNull != null thing is awful. But since .NET 2.0 there are "nullable value types"

e.g.

// C#.NET
int? myInt = null;
DateTime? myDateTime = null;

I assume that there exists something equivalent in VB.NET?

I would' expect for typed datasets that int? getter/setter is generated for nullable ints and int for not nullable ones ...

@David Piepgrass: Yes and no. DBNull.Value is OK when it would be compageable with null but: DBNull.Value != null (strange, I agree ;-))</description>
		<content:encoded><![CDATA[<p>You&#8217;re right, the DBNull != null thing is awful. But since .NET 2.0 there are &#8220;nullable value types&#8221;</p>
<p>e.g.</p>
<p>// C#.NET<br />
int? myInt = null;<br />
DateTime? myDateTime = null;</p>
<p>I assume that there exists something equivalent in VB.NET?</p>
<p>I would&#8217; expect for typed datasets that int? getter/setter is generated for nullable ints and int for not nullable ones &#8230;</p>
<p>@David Piepgrass: Yes and no. DBNull.Value is OK when it would be compageable with null but: DBNull.Value != null (strange, I agree ;-))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Piepgrass</title>
		<link>http://www.zorched.net/2005/11/17/net-nullable-types-and-dbnull-expose-design-flaws/comment-page-1/#comment-11200</link>
		<dc:creator>David Piepgrass</dc:creator>
		<pubDate>Wed, 19 Mar 2008 19:18:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/?p=12#comment-11200</guid>
		<description>You are incorrect in saying "As you can see, we can’t have a null value type. So, you can see why the DBNull was added, because .NET needed a way to represent a NULL database value." No, DBNull was not needed. DataRow["column"] returns an object (a reference type), therefore it could hold null. I have no idea why somebody at Microsoft invented DBNull, because the regular null value would have worked just fine. My hypothesis: it was an idiot.</description>
		<content:encoded><![CDATA[<p>You are incorrect in saying &#8220;As you can see, we can’t have a null value type. So, you can see why the DBNull was added, because .NET needed a way to represent a NULL database value.&#8221; No, DBNull was not needed. DataRow["column"] returns an object (a reference type), therefore it could hold null. I have no idea why somebody at Microsoft invented DBNull, because the regular null value would have worked just fine. My hypothesis: it was an idiot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad</title>
		<link>http://www.zorched.net/2005/11/17/net-nullable-types-and-dbnull-expose-design-flaws/comment-page-1/#comment-11069</link>
		<dc:creator>Brad</dc:creator>
		<pubDate>Thu, 22 Nov 2007 06:30:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/?p=12#comment-11069</guid>
		<description>An interesting read and I agree with many things you say but I thought I would correct one small thing.  Int32 is not a reference type that corresponds to int as a value type.  Similarly, your claim of the difference between string and String is flawed.  int and string are language-specific aliases for the value type Int32 and the reference type String correspondingly.

int i;

and

Int32 i;

will compile as identical code and become

System.Int32 i;

In VB.Net the aliases are Integer and String for these two types and in both languages, these aliases serve little purpose beyond provide familiarity to people migrating from non-.Net languages.

Strings are not value types at all regardless of the upper or lowercase s.</description>
		<content:encoded><![CDATA[<p>An interesting read and I agree with many things you say but I thought I would correct one small thing.  Int32 is not a reference type that corresponds to int as a value type.  Similarly, your claim of the difference between string and String is flawed.  int and string are language-specific aliases for the value type Int32 and the reference type String correspondingly.</p>
<p>int i;</p>
<p>and</p>
<p>Int32 i;</p>
<p>will compile as identical code and become</p>
<p>System.Int32 i;</p>
<p>In VB.Net the aliases are Integer and String for these two types and in both languages, these aliases serve little purpose beyond provide familiarity to people migrating from non-.Net languages.</p>
<p>Strings are not value types at all regardless of the upper or lowercase s.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geoff Lane</title>
		<link>http://www.zorched.net/2005/11/17/net-nullable-types-and-dbnull-expose-design-flaws/comment-page-1/#comment-9</link>
		<dc:creator>Geoff Lane</dc:creator>
		<pubDate>Fri, 18 Nov 2005 21:52:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/?p=12#comment-9</guid>
		<description>It's possible in many cases to "program defensively" in such a way that null values are basically never returned. But there are some applications where null values (especially in a database) are required.

I also completely agree with you about performance. Good design is the place  to start, worry about optimizing only when you find problem areas.

I built a data collection and reporting tool where we needed to be able to represent a NULL value in the database to the user as an unanswered question. Of course without NULL value types, you have to either represent it in the database as a "magic number" or create some sort of wrappers around all of your integral values and have a "magic number" in the code. (Hint, doing it in the database makes reporting off the data VERY difficult) Of course Nullable negates the necessity of having this "magic number" hack in place, so it's valuable in that sense. 

I just don't think it's necessary to require any of these Nullable/DBNull/Wrapper Object workarounds. If .NET provided a corollary reference type for all of the value types and would allow null references of these reference types, we could handle it ourselves. Minimzing/removing the use or value types because of the difference in semantics for copying, calling methods, etc has the side benefit of decreasing surprise.</description>
		<content:encoded><![CDATA[<p>It&#8217;s possible in many cases to &#8220;program defensively&#8221; in such a way that null values are basically never returned. But there are some applications where null values (especially in a database) are required.</p>
<p>I also completely agree with you about performance. Good design is the place  to start, worry about optimizing only when you find problem areas.</p>
<p>I built a data collection and reporting tool where we needed to be able to represent a NULL value in the database to the user as an unanswered question. Of course without NULL value types, you have to either represent it in the database as a &#8220;magic number&#8221; or create some sort of wrappers around all of your integral values and have a &#8220;magic number&#8221; in the code. (Hint, doing it in the database makes reporting off the data VERY difficult) Of course Nullable negates the necessity of having this &#8220;magic number&#8221; hack in place, so it&#8217;s valuable in that sense. </p>
<p>I just don&#8217;t think it&#8217;s necessary to require any of these Nullable/DBNull/Wrapper Object workarounds. If .NET provided a corollary reference type for all of the value types and would allow null references of these reference types, we could handle it ourselves. Minimzing/removing the use or value types because of the difference in semantics for copying, calling methods, etc has the side benefit of decreasing surprise.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brennan Stehling</title>
		<link>http://www.zorched.net/2005/11/17/net-nullable-types-and-dbnull-expose-design-flaws/comment-page-1/#comment-8</link>
		<dc:creator>Brennan Stehling</dc:creator>
		<pubDate>Fri, 18 Nov 2005 17:26:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.zorched.net/?p=12#comment-8</guid>
		<description>So far everything I have done with .NET 2.0 has been with a Stored Procedures in SQL Server 2000.  And I always wrap my columns which could be null with COALESCE and give it a default value, even if it is an empty String.  I did not want to even touch the situation with nulls.  My policy with objects is to prevent null values from even being possible.  I always construct my variables to some default and the Properties sometimes prevent a null value from replacing the non-null value.  It depends on each case.  I never want to check if a value returned from a method is a null.  Like when I return collections, if there are no values I just return an empty collection, so I can call that function from a foreach loop without checking for a null.  For strings I return String.Empty, etc.  My code has worked quite well, and it is quite fast.  I also never use string, and instead use String.  I do not care about optimizations through nuances with value types.  I find I get greater performance gains by taking my time to design a caching mechanism which cuts down on the db calls.  That is where 95% of your latency will be anyway.</description>
		<content:encoded><![CDATA[<p>So far everything I have done with .NET 2.0 has been with a Stored Procedures in SQL Server 2000.  And I always wrap my columns which could be null with COALESCE and give it a default value, even if it is an empty String.  I did not want to even touch the situation with nulls.  My policy with objects is to prevent null values from even being possible.  I always construct my variables to some default and the Properties sometimes prevent a null value from replacing the non-null value.  It depends on each case.  I never want to check if a value returned from a method is a null.  Like when I return collections, if there are no values I just return an empty collection, so I can call that function from a foreach loop without checking for a null.  For strings I return String.Empty, etc.  My code has worked quite well, and it is quite fast.  I also never use string, and instead use String.  I do not care about optimizations through nuances with value types.  I find I get greater performance gains by taking my time to design a caching mechanism which cuts down on the db calls.  That is where 95% of your latency will be anyway.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
