Re: Coding standards proposal, usage of "this"

Christian Biesinger via Gdb-patches
2021-08-16T16:41:40Z

On Fri, Aug 13, 2021 at 10:27 AM Simon Marchi via Gdb-patches
<gdb-patches@sourceware.org> wrote:
>
> Hi all,
>
> Here's something I had in mind for a while. We don't consistently use
> `this` when referring to fields or methods of the current object. I
> never now if I should use it or not, or point it out in review. I
> therefore propose these rules so that we have something to refer to.
>
> - Use `this` when referring to a data member that is not prefixed by
> `m_`. Rationale: without `this`, it's not clear that you are
> referring to a member of the current class, versus a local or global
> variable.
> - Don't use `this` when referring to a data member that is prefixed by
> `m_`. Rationale: the prefix already makes it clear that you are
> referring to a member of the current class, so adding `this` would
> just add noise.

Those two seem good.

> - Use `this` when referring to a method of the current class.
> Rationale: without `this, it's not clear that you are referring to a
> method of the current class, versus a free function.

I'm not really a fan of this, and I am also not aware of other
projects using such a style. Since this makes calling member functions
more verbose/uglier than calling free functions, this would also
discourage member functions. Is there a need to distinguish these?

Christian