New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
In bigger projects involving many developers, I find readability much more important than "this has a special meaning in other languages" (who cares about other languages) and "internal consistency" arguments. We read code 10x more often than we write code, and it is important to quickly know what an identifier represents. this/self enables a reader to quickly know that the identifier is the receiver. I don't see why naming the receiver this or self would be of such importance that it warrants a section of its own in the idiomatic golang style guide. |
We've been writing Go code for a decade with a convention of not using |
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: