Hacker News new | past | comments | ask | show | jobs | submit login

I think the reference to the refactoring in Visual Studio is a bit bogus in that it doesn't really imply anything about preference, you can swap between explicit and implicit. You can even specify which preference you prefer Implicit or Explicit typing for automatic code cleanup.

I've never really struggled with this in C# where nearly everything is implicitly typed. Never been a problem in non editor code views ( like github ) either. One of the major benefits, not mentioned, is when you change the type of something it doesn't cause needless code churn.

There are only a few things where I've seen it be a problem is for new people to programming where even remembering all the basic types is still a significant cognitive load and templated types look like unholy magic. They'd struggle to know what var sum = 1 + 2 + 3 would result in and really want to know.

The other, in C#, is where you end up with a IEnumerable instead of a List. This can result in some not so nice side effects




Visual Studio defaults to complaining about using var. The MSDN article I linked recommends not using var unless you have to. It seems quite clear what their preference is.


where does it say not to use it unless you have to ? They use it everywhere :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: