proposal: wiki: CodeReviewComments: remove guideline against 'this' / 'self' receiver names #38550
Comments
I've always felt an added burden when reading method code which doesn't use a predictable receiver name. Especially as you need to see clearly where a method alters its object's state. Worse still when the name is one letter among other single-letter names! |
The wiki page is a style guideline, and as it says the Go style is not to use names like I believe that the explanation is accurate. At least in C++, virtual methods are special, and the name If you want to write code that uses a different style, go ahead. You can also simply ignore the associated lint errors. |
The current style guideline has the advantage of internal consistency: the naming convention for a parameter is the same whether or not it's the receiver. This makes sense to me, since in Go the receiver behaves no differently from other parameters. Also for what it's worth, I've had substantial experience with both Python and C++ and I still prefer the Go style. It feels odd now to name all method receivers the same, even ones of completely unrelated types. |
The page at https://github.com/golang/go/wiki/CodeReviewComments#receiver-names has this to say about receiver names for struct methods:
This explanation was added in #28475.
But I don't believe this is a good argument:
this
pointers; andIn fact, there are benefits to using
self
/this
:I am interested in removal of this blessed guideline as a first prerequisite towards removing this as a default lint rule in vet and in other tools.
(However, I would support a vet rule enforcing that the names
this
/self
are only used with pointer receivers, for the same reasons above.)The text was updated successfully, but these errors were encountered: