The var keyword was invented in order to support dynamic types, not to replace the declaration of every local variable.
The reason I dislike it is because I believe it promotes laziness and needlessly obfuscates the code. The difference between
var request = new WebClient(); and WebClient request = new WebClient(); is negligable, so why not declare it properly?
Take these examples:
var provider = providerFactory.Create();
var customer = base.CreateCustomer();
As a developer seeing this code for the first time, what type is provider/customer? The only way of knowing is by looking up the declaration of Create/CreateCustomer. For the sake of a few keystrokes, you have made the code considerably harder to maintain.
Additionally, the general argument for var seems to be that the compiler and VS intellisense will inferring the type for you, but that doesn't help me if I am viewing it outside devenv (eg. comparing two versions of a source file in subversion).
Nick Baker: Xbox Architecture
Dec 03, 2009 at 9:37 AMThe 360's hardware failures come from problems in the production line, not it's architecture.
Exposing/Consuming RSS/ATOM using WCF 3.5 & Silverlight 2
Apr 15, 2008 at 3:04 PMThe reason I dislike it is because I believe it promotes laziness and needlessly obfuscates the code. The difference between var request = new WebClient(); and WebClient request = new WebClient(); is negligable, so why not declare it properly?
Take these examples:
var provider = providerFactory.Create();
var customer = base.CreateCustomer();
As a developer seeing this code for the first time, what type is provider/customer? The only way of knowing is by looking up the declaration of Create/CreateCustomer. For the sake of a few keystrokes, you have made the code considerably harder to maintain.
Additionally, the general argument for var seems to be that the compiler and VS intellisense will inferring the type for you, but that doesn't help me if I am viewing it outside devenv (eg. comparing two versions of a source file in subversion).
Exposing/Consuming RSS/ATOM using WCF 3.5 & Silverlight 2
Apr 15, 2008 at 2:39 AMHaving said that...
var request = new WebClient();
?? Way to promote terrible programming practices.
Developers for Developers (Devs4Devs) Series - "SharePoint Development -Making Sense of it All&
Jan 18, 2008 at 1:16 AMNo worries Dave. What do you mean by the by the Presentation Templates, though? I'm not familiar with the term. Is it an SP1 thing?
On a side note, how is GFW.com put together. Are they using a filter/module to fix up the "/Pages/" in their URLs or some other trickery?
Cheers for posting the video!
Developers for Developers (Devs4Devs) Series - "SharePoint Development -Making Sense of it All&
Jan 17, 2008 at 12:55 AM