<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.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>Stretching Type Inference</title><link>http://msmvps.com/blogs/paulomorgado/archive/2008/04/22/stretching-type-inference.aspx</link><description>Note: Code in italics is not actual C# 3.0 syntax. Local Variable Type Inference C# 3.0 brought us local variable type inference mainly because of LINQ . The output of a query can vary from an IEnumerable&amp;lt;T&amp;gt; or an IQueryable&amp;lt;T&amp;gt; to a single</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Reflective Perspective - Chris Alcock  &amp;raquo; The Morning Brew #81</title><link>http://msmvps.com/blogs/paulomorgado/archive/2008/04/22/stretching-type-inference.aspx#1603666</link><pubDate>Fri, 25 Apr 2008 07:30:33 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1603666</guid><dc:creator>Reflective Perspective - Chris Alcock  » The Morning Brew #81</dc:creator><description>&lt;p&gt;Pingback from &amp;nbsp;Reflective Perspective - Chris Alcock &amp;nbsp;&amp;amp;raquo; The Morning Brew #81&lt;/p&gt;
&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1603666" width="1" height="1"&gt;</description></item><item><title>re: Stretching Type Inference</title><link>http://msmvps.com/blogs/paulomorgado/archive/2008/04/22/stretching-type-inference.aspx#1603329</link><pubDate>Thu, 24 Apr 2008 21:38:35 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1603329</guid><dc:creator>Paulo Morgado</dc:creator><description>&lt;p&gt;In fact, some type inference occurs when you don't specify the type parameter, but it's because you already did it somewhere before.&lt;/p&gt;
&lt;p&gt;I've also considered &amp;quot;private var&amp;quot; instead of just &amp;quot;private&amp;quot; but came to the conclusion that it's not needed.&lt;/p&gt;
&lt;p&gt;When defining a local variable &amp;quot;var&amp;quot; is needed to desambiguate if you are defining a variable or assigning a previous defined variable or parameter, which doesn't occur when defining a field. In fact, there are people that think &amp;quot;var&amp;quot; should not exist, but I don't agree with that.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1603329" width="1" height="1"&gt;</description></item><item><title>re: Stretching Type Inference</title><link>http://msmvps.com/blogs/paulomorgado/archive/2008/04/22/stretching-type-inference.aspx#1603009</link><pubDate>Thu, 24 Apr 2008 16:17:15 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1603009</guid><dc:creator>Justin Lee</dc:creator><description>&lt;p&gt;With regards to the &amp;quot;Method Output And Parameter Type Inference&amp;quot;, technically we could already do so with Generic Methods and Generic Parameters.&lt;/p&gt;&lt;pre&gt;   private bool CreateList&amp;lt;T&amp;gt;(out T list)
   {
      list = new T();
      return true;
   }
   private void ProcessList&amp;lt;T&amp;gt;(ref T list)
   {
         // ...
   }
   private T TransformList&amp;lt;T&amp;gt;(T list)
   {
      return list;
   }&lt;/pre&gt;
&lt;p&gt;Or something along those lines.&lt;/p&gt;
&lt;p&gt;And might I add it probably would be syntactically correct if this line: &amp;nbsp; &amp;nbsp; &lt;/p&gt;&lt;pre&gt;   private listOfStuff = new List&amp;lt;Stuff&amp;gt;();&lt;/pre&gt;
&lt;p&gt;was like this instead:&lt;/p&gt;&lt;pre&gt;   private var listOfStuff = new List&amp;lt;Stuff&amp;gt;();&lt;/pre&gt;
&lt;p&gt;But definitely, I would like to see &amp;quot;var&amp;quot; being stretched to its limits in terms of type inference. It would be interesting to see how much we can infer statically, instead of going dynamic.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1603009" width="1" height="1"&gt;</description></item><item><title>re: Stretching Type Inference</title><link>http://msmvps.com/blogs/paulomorgado/archive/2008/04/22/stretching-type-inference.aspx#1602329</link><pubDate>Thu, 24 Apr 2008 08:15:14 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1602329</guid><dc:creator>Paulo Morgado</dc:creator><description>&lt;p&gt;Hi Bart,&lt;/p&gt;
&lt;p&gt;I just let my mind run wild from something that looked nice and useful to the scary places it could lead us to. :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1602329" width="1" height="1"&gt;</description></item><item><title>re: Stretching Type Inference</title><link>http://msmvps.com/blogs/paulomorgado/archive/2008/04/22/stretching-type-inference.aspx#1602244</link><pubDate>Thu, 24 Apr 2008 06:57:02 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1602244</guid><dc:creator>Bart</dc:creator><description>&lt;p&gt;Hi Paulo,&lt;/p&gt;
&lt;p&gt;Some nice thoughts but there seem to be tons of things that make this rather difficult to say the least.&lt;/p&gt;
&lt;p&gt;My main concern is the fact that a sole &amp;quot;new()&amp;quot; doesn&amp;#39;t have a type as all expressions in C# do today. This would require type information to flow in the opposite direction, which it never did and IMO never should. It&amp;#39;s similar to why LINQ has the from clause first in order to make the type information flow naturally.&lt;/p&gt;
&lt;p&gt;To point out a concrete problem:&lt;/p&gt;&lt;pre&gt;   public void SomeMethod()
   {
       AnotherMethod(new());
   }
   private void AnotherMethod(List&amp;lt;string&amp;gt; arg)
   {
       // ...
   }&lt;/pre&gt;
&lt;p&gt;will break as soon as you get new conflicting overloads for AnotherMethod which makes reasoning about code really hard. Every time you add a method you risk breaking something somewhere else (luckily you didn&amp;#39;t make it public :-)). Also refactoring becomes trickier, e.g. when you decide to switch a &amp;quot;type-inferred field&amp;quot; from a concrete class to an abstract class or interface.&lt;/p&gt;
&lt;p&gt;With things like:&lt;/p&gt;&lt;pre&gt;&amp;nbsp; Point p = new(1, 1);&lt;/pre&gt;
&lt;p&gt;and&lt;/p&gt;&lt;pre&gt;  Dictionary&amp;lt;Point, Stack&amp;lt;Person&amp;gt;&amp;gt; v = new();&lt;/pre&gt;
&lt;p&gt;I can somewhat symphatize, and you could get rid of the &amp;quot; = new&amp;quot; portion in there but then we get dangerously close to C&amp;#39;s syntax which would at the very least be confusing because of semantic differences.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;-Bart&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1602244" width="1" height="1"&gt;</description></item><item><title>Stretching Type Inference</title><link>http://msmvps.com/blogs/paulomorgado/archive/2008/04/22/stretching-type-inference.aspx#1601895</link><pubDate>Thu, 24 Apr 2008 00:05:25 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1601895</guid><dc:creator>DotNetKicks.com</dc:creator><description>&lt;p&gt;You&amp;#39;ve been kicked (a good thing) - Trackback from DotNetKicks.com&lt;/p&gt;
&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1601895" width="1" height="1"&gt;</description></item></channel></rss>