Re: Coding standards proposal, usage of "this"

Luis Machado via Gdb-patches
2021-08-16T17:26:31Z

On 8/16/21 2:11 PM, Simon Marchi via Gdb-patches wrote:
> On 2021-08-16 1:06 p.m., John Baldwin wrote:
>> On 8/13/21 7:26 AM, Simon Marchi via Gdb-patches 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.
>>
>> These seem fine to me.
>>
>>> - 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.
>>
>> This one feels a bit odd to me, though it may just be something I'm not
>> used to. It is something I haven't seen used before in C++ at least.
>
> So, the first two seem to be more accepted, and this last one less. I'd
> be fine just going with the first two then (even though in my opinion
> the reason for using `this` to refer to a non-prefixed data member
> applies the same when referring to a non-prefied member function).

My 2 cents. I wouldn't mind the change, but having to remember when to
use "this" and when not to use it is worse to me than spending a couple
minutes trying to figure out why the code is the way it is.

I suppose it is just the nature of C++. Some constructs are just not
great when trying to read/parse them. I think the same happens with some
templates and lambda's. It might take a little bit to figure out where
the functions are defined.

Given GDB's code base is a mix of C and C++, wouldn't we risk having yet
another mix of new coding standards with old coding standards?