Friday August 28th

Thursday August 27th

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

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

6 comments

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.

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 :)

Heh, they better be sure to port the entire BCL to whatever langauges they might want to switch to in the future as well...

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.

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.

@timbolt: Of course not. I'm just saying that "var" isn't evil or just for LINQ as many argues.

Commenting on Stories is limited for now and will open up to those recommended by the community. Learn how
Loading DotNetKicks...
brought to you by the Kicks Network