I am writing in C#, but this question may apply to other languages as well.
public class Test
{
int a = 10; // I created 'a' here
public void M()
{
int a = 20; // I forgot that I already have 'a' in the class and I initial it again ;
// do other stuff with "a"...
}
}
This way isn't against the declaring space rule, so the compiler will have no problem with it. I know I could use this.a
if I want to access the a
outside M()
and they are not a variable actually.
My question is:
Is this way could make some people confused by allowing declare the same name in a sub scope? Will it be harder to debug or doing code review?
a
' then conflicts are much less likely. Also, use a linting tool, as suggested below. – GoatInTheMachine Jan 9 at 16:20