Module level variable shadowing
Walter Bright via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jun 25 17:41:34 PDT 2014
On 6/25/2014 4:03 PM, bearophile wrote:
> The simplest way to avoid that kind of bugs is give a "shadowing global x error"
> (similar to the shadowing errors D gives with foreach and with statements). But
> this breaks most existing D code.
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.
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.
More information about the Digitalmars-d
mailing list