<?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>C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/09/15/467695.aspx</link><description>Due to my upbringing in C/C++ somehow I feel uneasy whenever I see some like var a = 5; 
 I guess this is ok in scripting languages. So when I heard that C# 3.0 is going to support implicit types for local variables that made me feel uneasy. I installed</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/09/15/467695.aspx#9531234</link><pubDate>Sat, 04 Apr 2009 09:14:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9531234</guid><dc:creator>Waleed Eissa</dc:creator><description>&lt;p&gt;Totally agree with you, it makes the code far less readable (and actually makes look like JavaScript more than C#), it should only be used with anonymous types but no where else.&lt;/p&gt;
&lt;p&gt;It's already being abused, go to stackoverflow.com and view some C# related questions to see what I mean.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9531234" width="1" height="1"&gt;</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/09/15/467695.aspx#8675070</link><pubDate>Tue, 01 Jul 2008 07:42:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8675070</guid><dc:creator>Abhinaba Basu [MSFT]</dc:creator><description>&lt;p&gt;Mihai I do not aggree with you. You assumption is that all code is written by you or your immediate team. Unfortunately that is not the case in the real world. Code bases grow and move ownership. Soon you will land up having to own/debug/re-use/use other teams code who are not deligent in imposing those policies.&lt;/p&gt;
&lt;p&gt;With what you said the responsibility of language designers go away. Then why don't we have typedefs in C#?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8675070" width="1" height="1"&gt;</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/09/15/467695.aspx#8671920</link><pubDate>Mon, 30 Jun 2008 20:30:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8671920</guid><dc:creator>Mihai Danila</dc:creator><description>&lt;p&gt;Years ago, someone was telling me how he still liked the old C/C++ way of structuring their methods: the variable declarations at the top, and the code using them down below. To this, add the use of cryptic one-letter variable names and you've got your recipe for disaster.&lt;/p&gt;
&lt;p&gt;I'm not bringing this up just to point out how var forces you out of this pattern (though this is in itself a good point,) but rather to point out that writing readable code involves the use of policies by developer that are currently beyond what can be enforced by compilers.&lt;/p&gt;
&lt;p&gt;I hate to have to say it, but I'm never going to write with variable names like the one in the example. I always use descriptive variable names and descriptive method names. This is a matter of policy, policy that should be in place already at your workplace. Methods that grow large should be split into smaller methods, again, to enhance readability: yet another policy that you should have in mind when coding.&lt;/p&gt;
&lt;p&gt;The point you are trying to make here becomes more and more mute as we investigate each claim. Until the compiler learns to enforce the use of good variable names, I agree that there is much potential for writing cryptic code through the use of var, but that's as far as you should go with the claim. The decision of whether to use var should be made on a case by case basis. My feeling is that, if you're good enough of a coder to write elegant code, var won't stop you from getting there. On the contrary, it may well help alot.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8671920" width="1" height="1"&gt;</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/09/15/467695.aspx#8539579</link><pubDate>Fri, 23 May 2008 17:45:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8539579</guid><dc:creator>Jax</dc:creator><description>&lt;p&gt;to quote the MSDN documentation:&lt;/p&gt;
&lt;p&gt;&amp;quot;Overuse of var can make source code less readable for others. It is recommended to use var only when it is necessary, that is, when the variable will be used to store an anonymous type or a collection of anonymous types.&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/bb383973.aspx"&gt;http://msdn.microsoft.com/en-us/library/bb383973.aspx&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8539579" width="1" height="1"&gt;</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/09/15/467695.aspx#7213295</link><pubDate>Thu, 24 Jan 2008 02:34:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7213295</guid><dc:creator>Cal</dc:creator><description>&lt;p&gt;This whole discussion is frustrating to read and I belive it results from uninformed developers immediate reaction to the word &amp;quot;var&amp;quot; and how it works in C# 3.0.&lt;/p&gt;
&lt;p&gt;There is no ambiguity about the type of any variable declared with the &amp;quot;var&amp;quot; keyword. It MUST be initialized in the same statement. The value that the variable is being initialized to determines the type of the variable. &lt;/p&gt;
&lt;p&gt;Furthermore, please understand that C# is still strongly typed. This is not a late-bound typoe or a variant, everything is known by the compiler at compile-time. This is not the introduction of the nasty variant datatype into C#!&lt;/p&gt;
&lt;p&gt;I have still not decided if the var keyword should ever be used outside of the declaration for variables of anonymous types... I don't see why it shouldn't be used for most variables defined inside methods.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7213295" width="1" height="1"&gt;</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/09/15/467695.aspx#7132221</link><pubDate>Wed, 16 Jan 2008 18:47:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7132221</guid><dc:creator>Peter</dc:creator><description>&lt;p&gt;var is one of the most bad things that was ever invented, becasue the lazy people that you are tryingto help are the most destructive persons in the developing team always...,&lt;/p&gt;
&lt;p&gt;so you are giving the killer a new weapon to use against the code...&lt;/p&gt;
&lt;p&gt;You really think that the person who prefer using var for ease will ever try to COMMENT his/her code....??!!!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7132221" width="1" height="1"&gt;</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/09/15/467695.aspx#7000153</link><pubDate>Sun, 06 Jan 2008 06:59:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7000153</guid><dc:creator>lubos</dc:creator><description>&lt;p&gt;I don't agree. anonymous types save you from useless class declarations which only hold data.&lt;/p&gt;
&lt;p&gt;for example, let's say you have JSON web service... you can just write&lt;/p&gt;
&lt;p&gt;return new { Username = &amp;quot;hello&amp;quot;, Password = &amp;quot;world&amp;quot; };&lt;/p&gt;
&lt;p&gt;no need for extra file to say what compiler can already figure out on its own.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7000153" width="1" height="1"&gt;</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/09/15/467695.aspx#6443375</link><pubDate>Wed, 21 Nov 2007 00:08:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6443375</guid><dc:creator>Matt</dc:creator><description>&lt;p&gt;Agreed, vars are rubbish. Okay, so it works for late-bound 'anonymous' types in LINQ but people are going to start using it in other scenarios making for anonymous code.&lt;/p&gt;
&lt;p&gt;C# is clean with a clear-cut path to achieve something so it keeps programmers egos out of the equation and makes for easy maintenance. I get the feeling that this addition is going to spoil that.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6443375" width="1" height="1"&gt;</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/09/15/467695.aspx#5689407</link><pubDate>Fri, 26 Oct 2007 13:50:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5689407</guid><dc:creator>Gaurav</dc:creator><description>&lt;p&gt;&amp;quot;Due to my upbringing in C/C++ somehow I feel uneasy whenever I see some like&lt;/p&gt;
&lt;p&gt;var a = 5;&amp;quot;&lt;/p&gt;
&lt;p&gt;Even I had the same feeling when I see *var* in C#.&lt;/p&gt;
&lt;p&gt;But to be very frank it is all about the name *var* and not about what it does.&lt;/p&gt;
&lt;p&gt;If it was voidobj or objvoid or something C like it would have been accepted with a techie smile :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5689407" width="1" height="1"&gt;</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/b/abhinaba/archive/2005/09/15/467695.aspx#4673290</link><pubDate>Fri, 31 Aug 2007 21:30:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4673290</guid><dc:creator>Brian Steffens</dc:creator><description>&lt;p&gt;Haha.. It'll be like the &amp;quot;dba&amp;quot; (huge quotes) that stores everything as a varchar because that way it will accept any value they pass.&lt;/p&gt;
&lt;p&gt;I agree with Alex on the naming. 'auto' is a much better word for that. Or even 'implied'. The second I looked up Linq and saw &amp;quot;var q = from etc&amp;quot; I groaned.&lt;/p&gt;
&lt;p&gt;I'm just happy that I don't have to collaborate much in my job so I won't have to deal with people using var for things that shouldn't be anonymous.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4673290" width="1" height="1"&gt;</description></item></channel></rss>