GoLand提示Receiver has generic name

GoLand Golang 大约 1039 字

The name of a method's receiver should be a reflection of its identity; often a one or two letter abbreviation of its type suffices (such as "c" or "cl" for "Client"). Don't use generic names such as "me", "this" or "self", identifiers typical of object-oriented languages that gives the method a special meaning. In Go, the receiver of a method is just another parameter and therefore, should be named accordingly. The name need not be as descriptive as that of a method argument, as its role is obvious and serves no documentary purpose. It can be very short as it will appear on almost every line of every method of the type; familiarity admits brevity. Be consistent, too: if you call the receiver "c" in one method, don't call it "cl" in another.

原因

Golang推荐的代码格式是尽量简洁的命名结构体的方法参数,不要使用面向对象中的thisself等词语。

解决

方法一(推荐)

将结构体的方法重命名为结构体的缩写。如Client结构体,可以命名为ccl

方法二

关闭GoLand提示。

Settings - Editor - Inspections - Go - Code Style issues - Receiver has generic name 取消勾选。

参考

https://github.com/golang/go/wiki/CodeReviewComments#receiver-names

阅读 142 · 发布于 2021-01-08

————        END        ————

扫描下方二维码关注公众号和小程序↓↓↓

扫描二维码关注我
昵称:
随便看看 换一批