Instance variables with @ (was: Re: why ; ?)

Michael Neumann mneumann at ntecs.de
Fri May 9 07:25:55 PDT 2008


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.

The next step would be to have "@" as a synonym for "this.", as typing
"this." all the time is either annoying and as such is ignored or leads
to less readable code (IMHO).

Regards,

   Michael



More information about the Digitalmars-d mailing list