You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@trafficserver.apache.org by James Peach <jp...@apache.org> on 2014/05/21 23:09:42 UTC

[RFC] coding style for member variable access

Hi all,

Leif pointed out that I've been doing this, and now I'd like to propose this as an official style guideline.

	Within a class member function, access to class members should use the explicit "this->foo" syntax.

The rationale for this is that it makes it blindingly obvious that class members are being accessed in a way that naming conventions do not. We do not have a consistent naming convention for member variables, and at any rate, those conventions never apply to accessing member functions. Our code is often difficult to read because it takes a long time to figure out whether names that are in scope are members, local variables, or file-locals.

Obviously, there are cases where using "this->" is overkill, so I'm happy for this to be a judgement call.

J

Re: [RFC] coding style for member variable access

Posted by John Plevyak <jp...@gmail.com>.
I'm with Brian.  You need to do this some time with templates and it seems
busy to me.  However there are probably exceptions...
On May 21, 2014 2:31 PM, "Brian Geffon" <br...@apache.org> wrote:

> I think this-> is incredibly ugly an unnecessary, what does it really get
> us? It will be become convention just as appending a underscore or adding
> m_ in front of the name. In my opinion this-> should only be used in
> situations where you need to disambiguate between variable names and not as
> a convention for member variables.
>
> Brian
>
>
> On Wed, May 21, 2014 at 2:09 PM, James Peach <jp...@apache.org> wrote:
>
> > Hi all,
> >
> > Leif pointed out that I've been doing this, and now I'd like to propose
> > this as an official style guideline.
> >
> >         Within a class member function, access to class members should
> use
> > the explicit "this->foo" syntax.
> >
> > The rationale for this is that it makes it blindingly obvious that class
> > members are being accessed in a way that naming conventions do not. We do
> > not have a consistent naming convention for member variables, and at any
> > rate, those conventions never apply to accessing member functions. Our
> code
> > is often difficult to read because it takes a long time to figure out
> > whether names that are in scope are members, local variables, or
> > file-locals.
> >
> > Obviously, there are cases where using "this->" is overkill, so I'm happy
> > for this to be a judgement call.
> >
> > J
> >
>

Re: [RFC] coding style for member variable access

Posted by Brian Geffon <br...@apache.org>.
I think this-> is incredibly ugly an unnecessary, what does it really get
us? It will be become convention just as appending a underscore or adding
m_ in front of the name. In my opinion this-> should only be used in
situations where you need to disambiguate between variable names and not as
a convention for member variables.

Brian


On Wed, May 21, 2014 at 2:09 PM, James Peach <jp...@apache.org> wrote:

> Hi all,
>
> Leif pointed out that I've been doing this, and now I'd like to propose
> this as an official style guideline.
>
>         Within a class member function, access to class members should use
> the explicit "this->foo" syntax.
>
> The rationale for this is that it makes it blindingly obvious that class
> members are being accessed in a way that naming conventions do not. We do
> not have a consistent naming convention for member variables, and at any
> rate, those conventions never apply to accessing member functions. Our code
> is often difficult to read because it takes a long time to figure out
> whether names that are in scope are members, local variables, or
> file-locals.
>
> Obviously, there are cases where using "this->" is overkill, so I'm happy
> for this to be a judgement call.
>
> J
>