explicit syntax for accessing class members and globals
Sean Kelly
sean at f4.ca
Tue Sep 5 13:06:01 PDT 2006
Serg Kovrov wrote:
> Hello D-people,
>
> It is strange I didn't encounter debates regarding subject so far. That
> I mean is a way to distinct class members and globals from local
> identifiers. For example forcing to use 'this' to access member data and
> methods.
>
> Then I first saw this approach in PHP (after C++ background), I was
> thinking that it is a stupidest idea - to type (and see) 'this->'
> allover again. But in time I get used to it and do really appreciate it.
It's obviously not enforced by the compiler, but I prefer a naming
convention to distinguish class member data from other data. Prefixing
"this." to everything is relatively verbose, and the compiler still
won't catch all bugs if you have a local variable with the same name as
a class member variable (though I believe this is actually a "shadowing"
error now). In any case, the convention I use is:
class C
{
int m_val1; // "m_" prefix for class members
static int sm_val2; // "sm_" prefix for static members
}
Sean
More information about the Digitalmars-d
mailing list