To “var” or not to “var”, is that really the question?

added by jgauffin
8/20/2012 9:53:15 AM


A different take on whether you should use the "var" keyword or not in your code.


8/20/2012 9:52:14 AM
I don't think there's anything wrong with using var, and I think it can actually make code *more* readable vs casting between (for instance) interfaces and classes that implement them.

8/20/2012 9:59:04 AM
That makes two of us. :D I really love that ending motivation. I wonder which C# language features he uses? I bet he's only using .NET v1.1 features :)

8/20/2012 11:07:19 AM
Heh, they better be sure to port the entire BCL to whatever langauges they might want to switch to in the future as well...

8/20/2012 5:54:30 PM
He makes a good point. A lot of people attack the use of 'var' because, they say, it leads to hard-to-read code. In reality, sometimes people write unreadable code and var can make that more unreadable. However, focussing on 'var' in these situations is wrong. Focussing on the underlying readability problem is the correct approach.

8/27/2012 9:04:44 AM
Like in any language, my personal experience has always been the proper readability of the variables themselves. Having good descriptions for variable names is what helps me out the most. I could care less whether it's var, int, char, string, etc. Don't get me wrong, it helps no doubt, however it is not the end all be all of naming conventions IMHO.

8/27/2012 11:26:14 AM
@timbolt: Of course not. I'm just saying that "var" isn't evil or just for LINQ as many argues.