On 08/20/2011 06:54 AM, bearophile wrote:
nsf:

> > Well, D currently says I can't shadow variables:
> Right, that's a third way to shadow variables that D forbids, thank
> you. But in my post I've shown other kinds of shadowing that
> currently D accepts. Shadowing global variables has caused some
> problems in my C code. One good commercial C lint lists all such
> cases with a warning.

In some cases, shadowing can be handy for code generation via string mixins (the shadowing that is disallowed, not the shadowing of globals). But it has also statically caught what would have been a bug in two or three cases. I do not mind if the compiler ensures that there is no shadowing of globals, because

1. I typically have almost no globals.
2. I don't name globals in a way that is likely to interfere.


Disallowing shadowing of variables inside nested functions might be annoying though, especially if it would apply to parameters as well.


> > which pisses me off personally. It's such a handy feature.
> It's a handy anti-feature, good source of bugs. Style guides suggest
> to rename one of them. If I see production C/C++ code that does that,
> I rename one of the two variables. In Haskell in your situation you
> are allowed to use x and x'.

Which would be really nice to have in D too. Afaik all it would require would be a simple change to the lexer.

Reply via email to