Receiver Naming
ID |
go.naming_receiver |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Go |
Tags |
naming |
Description
Reports a method receiver named with a non-idiomatic identifier such as this, self or
me.
Rationale
Go is not class-oriented: a receiver is just the first parameter, and the convention is a
short, type-derived name (func (s *Server), func (b *Buffer)). Borrowing this or self
from other languages reads as a foreign idiom and conveys no extra meaning.
// Bad
func (this *Server) Start() {} // FLAW
func (self *Server) Stop() {} // FLAW
// Good
func (s *Server) Start() {} // OK
func (srv *Server) Stop() {} // OK
Remediation
Rename the receiver to a short, type-derived identifier (one or two letters from the type name).