<?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/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>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#467717</link><pubDate>Thu, 15 Sep 2005 20:14:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:467717</guid><dc:creator>Jeff Parker</dc:creator><description>I have to agree with you I am not a fan of vars, I see nothing but trouble with it. &lt;br&gt;&lt;br&gt;What is wrong with the current way of just using an object. I guess I would want to know more the reason for it.</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#467737</link><pubDate>Thu, 15 Sep 2005 20:40:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:467737</guid><dc:creator>Mike</dc:creator><description>I don't think var was designed to be used like in your example. The main purpose for var may be this:&lt;br&gt;&lt;br&gt;var contacts =&lt;br&gt;    from c in customers&lt;br&gt;    where c.State == &amp;quot;WA&amp;quot;&lt;br&gt;    select new { c.Name, c.Phone };&lt;br&gt;&lt;br&gt;The part new { c.Name, c.Phone } declares and instantiates an anonymous type. Additionally the query probably returns a collection of that anonymous type so there is no way do declare the variable contacts other than by using var.&lt;br&gt;</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#467757</link><pubDate>Thu, 15 Sep 2005 21:06:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:467757</guid><dc:creator>Des Browne</dc:creator><description>C/C++ was my bread and butter when I was at uni, its explicitly typed nature was great to learn with. When I moved to c# I started having to write things like:&lt;br&gt;&lt;br&gt;System.Collections.Generics.List&amp;lt;int&amp;gt; list = new System.Collections.Generics.List&amp;lt;int&amp;gt;();&lt;br&gt;&lt;br&gt;so I very much rather writting:&lt;br&gt;&lt;br&gt;var list = new System.Collections.Generics.List&amp;lt;int&amp;gt;();&lt;br&gt;&lt;br&gt;Intellisense makes this easy and straight forward, and with out it the new fuctional and LINQ language features would be almost useless</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#467786</link><pubDate>Thu, 15 Sep 2005 21:35:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:467786</guid><dc:creator>Rob Cannon</dc:creator><description>vars is not a variant or something like that.  It's just a compiler shortcut where the compiler looks at what you wrote and says &amp;quot;You are initializing this variable with a string, therefore it must be a System.String&amp;quot;.  So the IDL emitted by the compiler is EXACTLY the same as if you had written:&lt;br&gt;&lt;br&gt;string s = &amp;quot;hello&amp;quot;;&lt;br&gt;&lt;br&gt;It is misleading to say &amp;quot;once the implicit type has been inferred it does not change&amp;quot; because it could be construed that the inference happens at runtime.&lt;br&gt;&lt;br&gt;Now, you can complain that vars are not good for purposes of documentation and clear code!</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#467863</link><pubDate>Thu, 15 Sep 2005 23:06:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:467863</guid><dc:creator>Cory Nelson</dc:creator><description>I agree.  While var is definately useful for things like LINQ, it has incredible potential for abuse.&lt;br&gt;&lt;br&gt;I fear the day years from now, when my job will be maintaining someone's spaghetti code that uses nothing but var.</description></item><item><title>C# 3.0: Extension Method</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#467932</link><pubDate>Fri, 16 Sep 2005 00:31:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:467932</guid><dc:creator>I know the answer (its 42)</dc:creator><description>After the declaration of C# 3.0 I went ahead and installed the PDC bits. After reading through the language...</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#468156</link><pubDate>Fri, 16 Sep 2005 07:37:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:468156</guid><dc:creator>Pieter</dc:creator><description>I'm with you on this, not mad about the var idea, at least it is not the variant data type which would really have worried me.</description></item><item><title>C# 3.0: I like Extension Methods</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#468268</link><pubDate>Fri, 16 Sep 2005 11:35:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:468268</guid><dc:creator>I know the answer (its 42)</dc:creator><description>After the declaration of C# 3.0 I went ahead and installed the PDC bits. After reading through the language...</description></item><item><title>C# 3.0: Lambda expressions. I don't like it that much</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#469569</link><pubDate>Sat, 17 Sep 2005 00:56:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:469569</guid><dc:creator>I know the answer (its 42)</dc:creator><description>This is the my third post on the series of post I am making on C#3.0 after it got declared on PDC. See...</description></item><item><title>C# 3.0: I love object and collection initializers</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#470359</link><pubDate>Sat, 17 Sep 2005 18:36:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:470359</guid><dc:creator>I know the answer (its 42)</dc:creator><description>This is the my fourth post in the series of posts I am making on C#3.0. See the previous posts here,...</description></item><item><title>C# 3.0: I do not like Anonymous types</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#471102</link><pubDate>Mon, 19 Sep 2005 09:38:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:471102</guid><dc:creator>I know the answer (its 42)</dc:creator><description>This is the my fifth post in the series of posts I am making on the new features in C#3.0. See the previous...</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#477988</link><pubDate>Fri, 07 Oct 2005 00:21:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:477988</guid><dc:creator>Shaun</dc:creator><description>What? Are C# programmers turning into VB6 programmers? &lt;br&gt;&lt;br&gt;I left VB and moved to C# after it became apparent that the VB Community wanted frilly, feel-good features like the My namespace rather than power to create amazingly powerful things in less code.&lt;br&gt;&lt;br&gt;Anonmymous types will lead to crappy code and nothing less. And we could have had default interface implementation or MI instead.&lt;br&gt;&lt;br&gt;Foo!</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#481010</link><pubDate>Fri, 14 Oct 2005 15:11:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:481010</guid><dc:creator>jc</dc:creator><description>I agree with you, the code you wrote is crappy. But it is NOT C# 3.0 legal code.&lt;br&gt;&lt;br&gt;var a;&lt;br&gt;&lt;br&gt;will be rejected by the compiler, whereas&lt;br&gt;&lt;br&gt;var a = 3;&lt;br&gt;&lt;br&gt;will be accepted.&lt;br&gt;&lt;br&gt;IOW, you always know the type of the variable by looking at its declaration.</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#481061</link><pubDate>Fri, 14 Oct 2005 17:36:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:481061</guid><dc:creator>abhinaba</dc:creator><description>I fixed the syntax error. You need to have a assignment in the declaration of a var in C# 3.0</description></item><item><title>bad name, good feature</title><link>http://blogs.msdn.com/abhinaba/archive/2005/09/15/467695.aspx#4171866</link><pubDate>Wed, 01 Aug 2007 19:21:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4171866</guid><dc:creator>Alex</dc:creator><description>&lt;p&gt;Aside: C++0x is also planning to adopt the same mechanism but using the keyword 'auto'.&lt;/p&gt;
&lt;p&gt;You don't HAVE to use it just 'cos it's there you know. I think it'll save typing. But what on earth were they thinking naming it 'var'? (Which basically means 'variant' to programmers via Javascript but is NOT the same in this context.)&lt;/p&gt;
</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/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;
</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/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;
</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/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;
</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/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;
</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/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;
</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/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;
</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/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;
</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/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;
</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/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</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;
</description></item><item><title>re: C# 3.0 : I don't like vars</title><link>http://blogs.msdn.com/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;
</description></item></channel></rss>