Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

https://docs.microsoft.com/en-us/dotnet/csharp/programming-g...

> Use implicit typing for local variables when the type of the variable is obvious from the right side of the assignment, or when the precise type is not important.

> Do not use var when the type is not apparent from the right side of the assignment.

> Do not rely on the variable name to specify the type of the variable. It might not be correct.

Your example has me inferring the type from the method name which isn't dissimilar to what they are advising against here.

TBH I should have known I would get a comment like this, where everyone lives in utopia and everything is always obvious to another person, nobody ever had a bad nights sleep or not feeling their best etc etc.

There are plenty of times where it may not be obvious what the Type it is returning even with quite decent coding standards and in any event I think it helps readability and isn't a huge ask. You can get Resharper / Rider to do this as a project setting (Visual Studio can probably do this out of the box now) in your repo and then the IDE will just do it for you.



MS recommends suffixing `Async`, and VS by default names fields with underscore but the C# naming suggests Pascal. So referencing MS docs is hardly justification.


So? because you disagree with some parts of it, all of it is a bad idea? That is a poor argument.

I've justified quite clearly why I think it is a good idea and in my original post I said quite clearly "It is upto you". It is trivial to turn on in the IDE and it improves readability outside of the IDE.




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

Search: