On 02/11/2012 14:13, bearophile wrote:
Adam D. Ruppe:
D normally lets locals shadow globals silently - if you had
int g;
void main() {
int g;
}
that's ok normally so it isn't specific to with. This is a good thing
because it means adding a variable elsewhere won't annoyingly break
your functions.
You could argue that doing it on structs is a little harder to keep
track of than regular locals, but, meh.
I try to minimize (possibly to zero) the number of global
variables/constants, but I have had some troubles caused by silent
shadowing of global names by local names in functions.
Having global variables with the same name of local variables is
sometimes a source for troubles, so I try to keep their name distinct.
But I'd like D to spot such duplications (shadowing of a global) for me.
Bye,
bearophile
When talking about global variables are we talking about module scope
variables?
As I see the module as the most primary data encapsulation in D, I often
use module scope variables (in combo with static import).
I didn't know you could shadow globals and in my situation it sounds bug
prone.