Back to the basics: should I initialize my variables?
If you’re an old C++ programmer, then you know that you must always initialize your variables (this has been recommended by Scott Meyers in his Effective C++ book). Now, I must say that I don’t really have an opinion on this one. Generally, I tend do initialize all my (local) variables, though I’ve read that doing this is bad for performance. Now, I don’t really know if this is the case or not. There are other reports on this, but I’m not sure that the penalty hit you’ll get is not worthy when you think about the legibility of the code (if you ask me, there has been enough compiler versions releases for getting that problem solved – I don’t know if that is the case or not). What I can garantee is that you’ll get a CS0165 error if you try to use a variable that hasn’t been initialized.
So, the question remains: should we initialize variables? what I do is initialize all local variables (ie, variables declared on methods) and leave class fields as they are. Opinions?