Re: Coding standards proposal, usage of "this"

Paul Koning via Gdb-patches
2021-08-13T14:46:51Z

> On Aug 13, 2021, at 10:26 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.
> - 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.
>
> ...
>
> Any comments? My intention would be to add this to the coding standards
> on the wiki.

This roughly amounts to turning C++ coding conventions into those of Python. While I like the Python ones, it seems odd to force C++ style into something clearly not envisioned by its basic structure.

The fact that C++ requires "this" in a few obscure cases is due to messy add-ons like templates. I don't see that as a reason to put "this" everywhere else.

paul