Re: Module level variable shadowing

2014-06-29 Thread bearophile via Digitalmars-d
H. S. Teoh: I used to like this shadowing trick, until one day I got bit by this typo. From then on, I acquired a distaste for this kind of shadowing. See: https://d.puremagic.com/issues/show_bug.cgi?id=3878 Bye, bearophile

Re: Module level variable shadowing

2014-06-29 Thread Ary Borenszweig via Digitalmars-d
On 6/29/14, 3:24 PM, Jacob Carlborg wrote: On 2014-06-28 14:20, Ary Borenszweig wrote: In Ruby the usage of a variable is always prefixed: `@foo` for instance vars, `$foo` for global variable, `FOO` for constant. You can't make a mistake. It's... perfect :-) Oh, that's where you're wrong, ver

Re: Module level variable shadowing

2014-06-29 Thread Jacob Carlborg via Digitalmars-d
On 2014-06-28 14:20, Ary Borenszweig wrote: In Ruby the usage of a variable is always prefixed: `@foo` for instance vars, `$foo` for global variable, `FOO` for constant. You can't make a mistake. It's... perfect :-) Oh, that's where you're wrong, very wrong :). Take this for example: class Fo

Re: Module level variable shadowing

2014-06-29 Thread via Digitalmars-d
On Saturday, 28 June 2014 at 12:20:15 UTC, Ary Borenszweig wrote: On 6/28/14, 6:30 AM, Jacob Carlborg wrote: On 2014-06-28 08:19, dennis luehring wrote: thx for the examples - never though of these problems i personaly would just forbid any shadowing and single-self-assign and then having un

Re: Module level variable shadowing

2014-06-29 Thread dennis luehring via Digitalmars-d
Am 29.06.2014 08:06, schrieb Kapps: struct Foo { int a; this(this.a) { } } a parameter declaration with the name of the scope name??? totaly different to everything else???

Re: Module level variable shadowing

2014-06-28 Thread Kapps via Digitalmars-d
On Saturday, 28 June 2014 at 05:13:16 UTC, H. S. Teoh via Digitalmars-d wrote: Actually, this particular use case is very bad. It's just inviting typos, for example, if you mistyped "int a" as "int s", then you get: struct Foo { int a; this(int s) {

Re: Module level variable shadowing

2014-06-28 Thread dennis luehring via Digitalmars-d
Am 28.06.2014 14:20, schrieb Ary Borenszweig: On 6/28/14, 6:30 AM, Jacob Carlborg wrote: On 2014-06-28 08:19, dennis luehring wrote: thx for the examples - never though of these problems i personaly would just forbid any shadowing and single-self-assign and then having unique names (i use m_

Re: Module level variable shadowing

2014-06-28 Thread Ary Borenszweig via Digitalmars-d
On 6/28/14, 6:30 AM, Jacob Carlborg wrote: On 2014-06-28 08:19, dennis luehring wrote: thx for the examples - never though of these problems i personaly would just forbid any shadowing and single-self-assign and then having unique names (i use m_ for members and p_ for parameters etc.) or give

Re: Module level variable shadowing

2014-06-28 Thread dennis luehring via Digitalmars-d
Am 28.06.2014 11:30, schrieb Jacob Carlborg: On 2014-06-28 08:19, dennis luehring wrote: thx for the examples - never though of these problems i personaly would just forbid any shadowing and single-self-assign and then having unique names (i use m_ for members and p_ for parameters etc.) or gi

Re: Module level variable shadowing

2014-06-28 Thread Jacob Carlborg via Digitalmars-d
On 2014-06-28 08:19, dennis luehring wrote: thx for the examples - never though of these problems i personaly would just forbid any shadowing and single-self-assign and then having unique names (i use m_ for members and p_ for parameters etc.) or give a compile error asking for this.x or .x (ma

Re: Module level variable shadowing

2014-06-27 Thread dennis luehring via Digitalmars-d
Am 28.06.2014 07:11, schrieb H. S. Teoh via Digitalmars-d: On Sat, Jun 28, 2014 at 06:37:08AM +0200, dennis luehring via Digitalmars-d wrote: Am 27.06.2014 20:09, schrieb Kapps: [...] >struct Foo { > int a; > this(int a) { > this.a = a; > } >} > forgot that case -

Re: Module level variable shadowing

2014-06-27 Thread H. S. Teoh via Digitalmars-d
On Sat, Jun 28, 2014 at 06:37:08AM +0200, dennis luehring via Digitalmars-d wrote: > Am 27.06.2014 20:09, schrieb Kapps: [...] > >struct Foo { > > int a; > > this(int a) { > > this.a = a; > > } > >} > > > > forgot that case - but i don't like how its currently handled,

Re: Module level variable shadowing

2014-06-27 Thread dennis luehring via Digitalmars-d
Am 27.06.2014 20:09, schrieb Kapps: On Friday, 27 June 2014 at 08:24:16 UTC, dennis luehring wrote: Am 27.06.2014 10:20, schrieb dennis luehring: I think we hit the sweet spot at restricting shadowing detection to local scopes. sweet does not mean - use a better name or .x to avoid manualy h

Re: Module level variable shadowing

2014-06-27 Thread dennis luehring via Digitalmars-d
Am 27.06.2014 22:38, schrieb Tofu Ninja: On Friday, 27 June 2014 at 08:24:16 UTC, dennis luehring wrote: what i don't understand - why on earth should someone want to shadow a(or better any) variable at all? It can be useful if you are using mixins where you don't know what is going to be in t

Re: Module level variable shadowing

2014-06-27 Thread Meta via Digitalmars-d
On Friday, 27 June 2014 at 20:40:24 UTC, Walter Bright wrote: On 6/27/2014 1:38 PM, Tofu Ninja wrote: On Friday, 27 June 2014 at 08:24:16 UTC, dennis luehring wrote: what i don't understand - why on earth should someone want to shadow a(or better any) variable at all? It can be useful if you

Re: Module level variable shadowing

2014-06-27 Thread Walter Bright via Digitalmars-d
On 6/27/2014 1:38 PM, Tofu Ninja wrote: On Friday, 27 June 2014 at 08:24:16 UTC, dennis luehring wrote: what i don't understand - why on earth should someone want to shadow a(or better any) variable at all? It can be useful if you are using mixins where you don't know what is going to be in th

Re: Module level variable shadowing

2014-06-27 Thread Tofu Ninja via Digitalmars-d
On Friday, 27 June 2014 at 08:24:16 UTC, dennis luehring wrote: what i don't understand - why on earth should someone want to shadow a(or better any) variable at all? It can be useful if you are using mixins where you don't know what is going to be in the destination scope.

Re: Module level variable shadowing

2014-06-27 Thread Kapps via Digitalmars-d
On Friday, 27 June 2014 at 08:24:16 UTC, dennis luehring wrote: Am 27.06.2014 10:20, schrieb dennis luehring: I think we hit the sweet spot at restricting shadowing detection to local scopes. sweet does not mean - use a better name or .x to avoid manualy hard to detect problems - its like di

Re: Module level variable shadowing

2014-06-27 Thread dennis luehring via Digitalmars-d
Am 26.06.2014 02:41, schrieb Walter Bright: 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 lo

Re: Module level variable shadowing

2014-06-27 Thread dennis luehring via Digitalmars-d
Am 27.06.2014 10:20, schrieb dennis luehring: I think we hit the sweet spot at restricting shadowing detection to local scopes. sweet does not mean - use a better name or .x to avoid manualy hard to detect problems - its like disabled shadow detection in local scopes what i don't understand

Re: Module level variable shadowing

2014-06-27 Thread Jacob Carlborg via Digitalmars-d
On 2014-06-26 02:41, Walter Bright wrote: 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. No need to ha

Re: Module level variable shadowing

2014-06-26 Thread bearophile via Digitalmars-d
But having something enforced by the compiler is better. I meant, it could be better. Bye, bearophile

Re: Module level variable shadowing

2014-06-26 Thread bearophile via Digitalmars-d
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 gl

Re: Module level variable shadowing

2014-06-25 Thread Walter Bright via Digitalmars-d
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, wher

Re: Module level variable shadowing

2014-06-25 Thread H. S. Teoh via Digitalmars-d
On Wed, Jun 25, 2014 at 11:03:14PM +, bearophile via Digitalmars-d wrote: > While I try to minimize the number of module-level variables in D > code, sometimes they are present, and sometimes I have problems (bugs) > caused by unwanted shadowing of global names (or sometimes more > generally, n

Module level variable shadowing

2014-06-25 Thread bearophile via Digitalmars-d
While I try to minimize the number of module-level variables in D code, sometimes they are present, and sometimes I have problems (bugs) caused by unwanted shadowing of global names (or sometimes more generally, names from outer scopes, but this is less common): int x = 1; // ... void foo() {