Walter Bright:

I suggest that your issues with global variables can be mitigated by adopting a distinct naming convention for your globals. Frankly, I think a global variable named "x" is execrable style - such short names should be reserved for locals.

I don't use names like 'x' for the global variables, that was just an artificial example. But I am not yet using a naming convention for global variables (like using a "_g" suffix) and perhaps I should start using it. But having something enforced by the compiler is better.


D has scoped lookup. Taking your proposal as principle, where do we stop at issuing errors when there is the same identifier in multiple in-scope scopes? I think we hit the sweet spot at restricting shadowing detection to local scopes.

From the bugs I've had by unwanted shadowing global variables, the current spot of D doesn't look very sweet to me.

I'd like D to try some alternative point where to stop issuing those errors. I am not convinced the current design is the best one. Some kind of error for module-level shadowing could be an improvement over the current situation. I can be wrong of course, but I think it's a good idea to explore some more this little piece of the design space.

Bye,
bearophile

Reply via email to