|
Boost : |
Subject: Re: [boost] underscores in private class member names (was: [local] this_ or _this?)
From: Joshua Juran (jjuran_at_[hidden])
Date: 2011-05-01 02:41:57
On Apr 18, 2011, at 7:41 AM, Stewart, Robert wrote:
> Julian Gonggrijp wrote:
>>
>
>> All this talking of underscores makes me wonder about private class
>> members. Several authors advise to give them names with a prefix
>> underscore (followed by a lowercase letter). It does seem to have
>> clear advantages: it visually marks the members as implementation
>> details, and it also makes it easier to distinguish class member data
>> from arguments and locally declared variables in member functions.
>>
>> However, your opinions probably differ wildly on the matter.
>> Would you consider it good practice to give private class members a
>> name that starts with _[a-z] (regex)?
>
> Distinguishing private data members from local variables and formal
> parameters is useful. It creates a distinct "namespace" from local
> variable and formal parameter names. How to mark them is purely
> subjective. Some use the "m_" prefix, popularized by MFC and MSVC
> code generators, but I find that to be too much of a wart on the
> name. Some use "this->" as a prefix, so their data member names
> need no special marking.
>
> I like to distinguish protected and private data members but with a
> trailing underscore. I use a trailing underscore because it is less
> important than the data member's name. (I also use a preceding
> underscore for formal parameters to give them another "namespace."
> In that case, the underscore can't be on the end, of course.)
I precede data member names with 'its_' (for nouns) or 'it_' (for
boolean properties), e.g. its_window, it_is_selected. I chose third-
person usage (as opposed to, say, "my") to match 'this'. I like self-
documenting English notation. :-)
Josh
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk