Jay Pipes wrote:
> Hi all!
>
> We have a gap in our naming convention guidelines we'd like to fill in.
>
> How do you like to designate private member variables and methods of a
> class?
I would suggest to re-formulate this as "designate member variables and methods
of a class".
Maybe except PODs from this rule, since they are only intended to carry data.
> Currently, there are varying styles used in the code.
>
> Style #1:
>
> The m_ prefix style (see Diagnostics_area)
>
> class Diagnostics_area
> {
> ...
> private:
> /** Message buffer. Can be used by OK or ERROR status. */
> char m_message[DRIZZLE_ERRMSG_SIZE];
> ...
> }
++
I vote for this: I see a value in using prefixes for names to distinguish
between variables with different lifetime (auto variables use no prefix, m_ live
as long as the object lives, and g_ live for the duration of the program).
I see no value in using prefixes to distinguish between visibility or scope, so
static variables and global variables have the same prefix.
>
> Style #2:
>
> No name difference between public and private members
>
> Style #3:
>
> Use of an underscore prefix (proposed to be used)
>
> This would look like:
>
> class MyClass
> {
> private:
> /** Our internal Foo object. */
> Foo _foo;
> /** Helper method to initialize our foo. */
> void _initFoo();
> public:
> Foo &getFoo() {return _foo;}
> }
This is dangerously close to stepping on compiler implementation namespace. The
standard reserves symbols starting with __ (double underscores) and _
(underscore) plus capital letter for implementation purposes. With this, there
is a risk of introducing a symbol that is actually reserved by the compiler, but
which will go undetected until a platform or compiler appears that is using that
symbol. That can lead to hard to find bugs, for example if a macro and a
variable have the same name, but accidentally, the macro expands to something
that is a reasonable variable name.
I strongly suggest to stay away from any symbols beginning with underscore.
Just my few cents,
Mats Kindahl
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp
--
Mats Kindahl
Senior Software Engineer
Database Technology Group
Sun Microsystems
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp