Programming etiquette

Soldato
Joined
18 Oct 2002
Posts
15,861
Location
NW London
I am a C# programmer.
Yesterday I bought Resharper, which is a program that works in conjunction with Visual Studio and makes suggestions for improving your code.

The suggestion it keeps making is using implicit declaration vs explicit.

For example:

My code is completely explicit:
Code:
QuestionMonitorClass qm = new QuestionMonitorClass();

It suggested that I implicitly declare, as follows:

Code:
var qm = new QuestionMonitorClass();

What do you guys suggest?
Which is faster?
Which is better?
 
When you have a local variable used as your iterator in a for loop, it makes productivity sense in not having to be so manic over data types, as it's essentially a throw-away and bound by the limits of the range you're looping over, and trivial for the compiler/IDE to always accurately determine the data type necessary.

Now if you need to later change the for loop range to expand it, you don't have to worry that the data type of your iterator is or isn't going to overflow, it'll adjust on its own.

From you example, I can see the benefit of using 'var', instead of say 'int', in a for loop. But where else would you see a benefit?

I'm quite happy doing explicit declarations (its become a habit), but is it bad to be so explicit?

What other advantage could there be of using an implicit declaration, over explicit?

From what I can see, this is a very minor programming issue.
 
If you don't like it you can always turn that one off in the ReSharper settings though.

If you've just got ReSharper then start learning the keyboard shortcuts, it really does make using Visual Studio much more of a pleasurable experience and soon you'll wonder how you ever did without it!

I have just got Resharper and I'm still getting used to it. The right click menu has changed slightly, so I'm still getting to grips with it.

I think I will shut off that feature of the implicit declaration...I'm in the habit of declaring things explicitly and when recasting/converting types, I like to write code which explicitly does the conversion (rather than implicitly allowing the compiler to do this without me knowing).

One area where there seems to be a massive advantage is in For loops/counters and possible data type overflow errors.

Thanks for your input guys.
 
Here's another thing that ReSharper points out as a "problem" with my code:

It states that the following code breaks the naming rule:

Code:
int integerPartOfCustomerID = 4;
string stringPartOfCustomerID = zyz;

It doesnt like the idea of 2 consecutive upper case and wants to change the code to:

Code:
int integerPartOfCustomerId = 4;
string stringPartOfCustomerId = zyz;

Any opinions on this?
Should change the names of my variables (according to the above recommendation), in my entire project?
 
Back
Top Bottom