<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Non-nullable types</title><link>http://blogs.msdn.com/b/devdev/archive/2005/10/10/479272.aspx</link><description>If you write programs in C, C++, Java, or C#, you've gotten used to having the null value around. The null value is a special reserved reference (or pointer) value indicating that a reference does not refer to any object. It's useful for constructing</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Non-nullable types</title><link>http://blogs.msdn.com/b/devdev/archive/2005/10/10/479272.aspx#480690</link><pubDate>Thu, 13 Oct 2005 20:46:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:480690</guid><dc:creator>Stuart Ballard</dc:creator><description>The idea of supporting three types of reference is an interesting one; presumably they'd be string! (non-nullable) string? (explicitly nullable) and just plain string (unchecked).&lt;br&gt;&lt;br&gt;You could then arrange for any use of an unchecked type to produce a warning, which developers could choose to configure as an error instead using existing warn-as-error compiler settings.&lt;br&gt;&lt;br&gt;For value types the &amp;quot;!&amp;quot; would be redundant, but it seems to me it would be a good idea to allow it for consistency, and also support producing a warning if it's not used. This would actually make the current inconsistent behavior of nullable value types more consistent - currently you can't call methods on the underlying type directly on a nullable, but that would be the case on an explicitly-nullable reference too.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=480690" width="1" height="1"&gt;</description></item><item><title>re: Non-nullable types</title><link>http://blogs.msdn.com/b/devdev/archive/2005/10/10/479272.aspx#479321</link><pubDate>Mon, 10 Oct 2005 23:40:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:479321</guid><dc:creator>Lonnie McCullough</dc:creator><description>Better yet, the &amp;quot;required&amp;quot; constraint could just force the compiler to insert checks against null to all the required parameters, throwing ArgumentNullException as appropriate.  The &amp;quot;required&amp;quot; constraint would be visible in the editor through syntax assist, but would not really modify the type signature of the method because the null checks are performed by the method itself.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=479321" width="1" height="1"&gt;</description></item><item><title>re: Non-nullable types</title><link>http://blogs.msdn.com/b/devdev/archive/2005/10/10/479272.aspx#479320</link><pubDate>Mon, 10 Oct 2005 23:39:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:479320</guid><dc:creator>MSDNArchive</dc:creator><description>Thanks for your comments, Stuart. Backward compatibility is a difficult issue. The way Spec# in particular deals with it is to allow you to compile old code as C# but create a separate interface with updated signatures for these methods that is used by new code. They call these out-of-band specifications, and this is how they added non-null argument types to Framework methods. &lt;br&gt;&lt;br&gt;One alternative solution more suitable for direct inclusion in C# is to create three types of references: non-nullable, nullable, and unchecked. The original syntax would produce unchecked references, which are nullable and can also be implicitly narrowed to non-nullable values. I'm sure there are other solutions available as well.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=479320" width="1" height="1"&gt;</description></item><item><title>re: Non-nullable types</title><link>http://blogs.msdn.com/b/devdev/archive/2005/10/10/479272.aspx#479318</link><pubDate>Mon, 10 Oct 2005 23:35:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:479318</guid><dc:creator>Lonnie McCullough</dc:creator><description>I think this would be a great addition to C#.  Parameter modifiers that affect the actual type signature already exist in the &amp;quot;ref&amp;quot;, &amp;quot;out&amp;quot; and &amp;quot;params&amp;quot; keywords.  That last one is probably the closest in nature to the non-null type modifier because it requires compiler support to implement properly.  Something like the following would be in keeping with C#'s nature:&lt;br&gt;&lt;br&gt;public void Method( required string name ) {&lt;br&gt;}&lt;br&gt;&lt;br&gt;The compiler could then use static checks to determine if Method or some other override (that doesn't include the &amp;quot;required&amp;quot; constraint) should be called.  I definitely like putting basic constraints like this in the method signature itself.  It also saves a lot of checking against null.  Since the constraint modifies the signature of the method it would be easy to add these to current classes, while maintaing back-compat.  Would also be cool if you could call:&lt;br&gt;&lt;br&gt;obj.Method( required param )&lt;br&gt;&lt;br&gt;and have the compiler perform the null checks for you.  Makes calling the constained method from non-constrained overloads very easy.&lt;br&gt;&lt;br&gt;&lt;br&gt;-Lonnie&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=479318" width="1" height="1"&gt;</description></item><item><title>re: Non-nullable types</title><link>http://blogs.msdn.com/b/devdev/archive/2005/10/10/479272.aspx#479298</link><pubDate>Mon, 10 Oct 2005 22:50:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:479298</guid><dc:creator>Stuart Ballard</dc:creator><description>See Cyrus's blog entries from a few months back on why this is a good idea, but also why it's hard.&lt;br&gt;&lt;br&gt;My personal opinion is that it's impossible to do in C# because you can't do it *right* without breaking backward compatibility.&lt;br&gt;&lt;br&gt;Consider the simple example:&lt;br&gt;&lt;br&gt;public int GetLength(string s) {&lt;br&gt;  return s.Length;&lt;br&gt;}&lt;br&gt;&lt;br&gt;This is valid C# code today; backward compatibility dictates that it must continue to be valid and do the same thing it does today. But it instantly defeats the whole point of compiletime null checking because you have a possibly-null object being dereferenced right in front of your face.&lt;br&gt;&lt;br&gt;It's possible to arrange that you can't pass a null value to a function that specifically requests a string!-typed argument, but that doesn't help much if every single &amp;quot;.&amp;quot; in your program is still a potential landmine...&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=479298" width="1" height="1"&gt;</description></item></channel></rss>