Refactoring Tips - Tip 1






2.80/5 (10 votes)
Hi,I was thinking to wrtite a series of tips on Refactoring exercise from past couple of months.Here goes the result of that exerciseTip 1 Try to declare the variable close to its first value assignment.For eg :Try to avoid this - private void Method(){ int...
Hi,
I was thinking to wrtite a series of tips on Refactoring exercise from past couple of months.Here goes the result of that exercise
Tip 1
Try to declare the variable close to its first value assignment. For eg : Try to avoid this -private void Method()
{
int Var1;
int Var2;
int Var3;
//Some more statements
Var1 = 10;
}
Good Practice
private void Method() { int Var2; int Var3; //Some more statements int Var1; Var1 = 10; }This approach will help to increase the readability of the code snippet,Hence easy to maintain and enhance. I hope this helps. Regards, -Vinayak