Instance variables with @ (was: Re: why ; ?)
Bruce Adams
tortoise_74 at yeah.who.co.uk
Fri May 9 16:16:04 PDT 2008
On Fri, 09 May 2008 21:20:30 +0100, Nick Sabalausky <a at a.a> wrote:
> "Michael Neumann" <mneumann at ntecs.de> wrote in message
> news:g01mtk$1nvj$1 at digitalmars.com...
>> Nick Sabalausky wrote:
>> > // Note: untested
>> > class A {
>> > int i=0;
>> >
>> > void foo() {
>> > // Accidentially clobbers "this.i" aka "@i"
>> > for(i=0; i<77; i++)
>> > {/* Do stuff */}
>> > }
>> >
>> > invariant() {
>> > assert(this.i==0); // Fails after foo() is called
>> > }
>> > }
>> >
>> > I still like the @ thing, though.
>>
>> Very good example!
>>
>> A solution could be to force the programmer to use the "this." notation
>> or at least issuing a compiler warning if not done. The latter could be
>> implemented in the compiler without any changes to the syntax/language.
>>
I believe Walter disapproves of compiler warnings on principle. Its either
an error or it isn't.
I tend to disagree but on the otherhand I always code with -Werror and
frown at any warnings
emitted by anything so I guess deep down I really agree with him.
More information about the Digitalmars-d
mailing list