GoLand 提示 Receiver has generic name

GoLand Go About 1,041 words

错误信息

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.

原因

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

解决

方法一(推荐)

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

方法二

关闭GoLand提示。

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

参考

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

Views: 3,217 · Posted: 2021-01-08

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

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

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


Today On History
Browsing Refresh