Re: scope of variables
- Posted by DerekParnell (admin) Dec 30, 2010
- 2911 views
jeremy said...
To start the dialog, in what situation would it be beneficial to allow duplicate variable names of various types?
I believe it is not a good coding practice because it hinders, rather than enhances, readability of code. When the reader sees 'b = somefunc()' they might get confused if they missed seeing that 'b' was also declared in the local block.
However sometimes when code is 'copy&pasted', shadowed identifiers can get accidentally created - and the code still works. Ideally in that situation, the coder should re-factor the names to better reflect the copied code's new "environment".