Re: More name hiding

2011-08-20 Thread Mehrdad
>> Parameters shadowing outside members is pretty common and useful > How the hell is it useful? > If you have: > { > int x; > { > double x; // use x > } > } > And you comment out or remove "double x", you've just introduced a bug in your code I think you missed the word *M

Re: More name hiding

2011-08-20 Thread Timon Gehr
On 08/20/2011 08:37 PM, Timon Gehr wrote: On 08/20/2011 08:21 PM, bearophile wrote: Timon Gehr: In some cases, shadowing can be handy for code generation via string mixins (the shadowing that is disallowed, not the shadowing of globals). Making the language more forbidding makes the generati

Re: More name hiding

2011-08-20 Thread Timon Gehr
On 08/20/2011 08:21 PM, bearophile wrote: Timon Gehr: In some cases, shadowing can be handy for code generation via string mixins (the shadowing that is disallowed, not the shadowing of globals). Making the language more forbidding makes the generation of code simpler. But it's simpler to wr

Re: More name hiding

2011-08-20 Thread bearophile
Timon Gehr: > In some cases, shadowing can be handy for code generation via string > mixins (the shadowing that is disallowed, not the shadowing of globals). Making the language more forbidding makes the generation of code simpler. But it's simpler to write code that generates correct code, tha

Re: More name hiding

2011-08-20 Thread Timon Gehr
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 som

Re: More name hiding

2011-08-20 Thread Andrej Mitrovic
How the hell is it useful? If you have: { int x; { double x; // use x } } And you comment out or remove "double x", you've just introduced a bug in your code.

Re: More name hiding

2011-08-20 Thread Mehrdad
On 8/20/2011 3:46 AM, Kagamin wrote: Mehrdad Wrote: Even more common with constructor parameters and instance fields. If a naming convention encourages shadowing, it's a broken naming convention. I don't think a convention should /encourage/ shadowing per se, but I don't think it should discou

Re: More name hiding

2011-08-20 Thread Kagamin
Mehrdad Wrote: > Even more common with constructor parameters and instance fields. If a naming convention encourages shadowing, it's a broken naming convention.

Re: More name hiding

2011-08-19 Thread bearophile
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

Re: More name hiding

2011-08-19 Thread nsf
On Fri, 19 Aug 2011 11:07:12 -0400 bearophile wrote: > Some ways to face this problem: > > 1) Do nothing. > 2) Give optional explicit information about the source of all variable names > used in a function, using the optional @outer() I have proposed elsewhere. > 3) Statically disallow (gives a

Re: More name hiding

2011-08-19 Thread Mehrdad
On 8/19/2011 8:17 AM, Andrej Mitrovic wrote: It's not just globals. It's hiding fields as well: class A { int x; this() { int x; //<- hides this.x } } I've had this happen during a cut/paste session, which happens when I'm refactoring my code. I actually use this o

Re: More name hiding

2011-08-19 Thread Andrej Mitrovic
It's not just globals. It's hiding fields as well: class A { int x; this() { int x; // <- hides this.x } } I've had this happen during a cut/paste session, which happens when I'm refactoring my code.

More name hiding

2011-08-19 Thread bearophile
After translating some buggy C code (full of gotos and global variables) to D and going hunting for bugs for some time, I have grown a desire to write this post. Variable name hiding is a source of bugs. A typical example: int x; void foo() { int x = 5; // lot of code code here x++