golint の “don’t use leading k in Go names” とは?

Question: Question:

I was angry with golint saying don't use leading k in Go names . why is that?

Operation example:

$ cat leading_k.go 
package main

const kFoo = 1
$ golint leading_k.go 
leading_k.go:3:5: don't use leading k in Go names; var kFoo should be foo

Environment: Go 1.9.3

Answer: Answer:

This rule was originally prepared to suppress the method of prefixing k when expressing a constant in Hungarian notation. If you follow golint, revisit the nomenclature, such as simply naming it foo instead of using the Hungarian notation k .

However, even if it is not Hungarian notation, a variable name such as kB will get caught in this rule. If the second character is lowercase, this rule will not be caught, so you can avoid it by changing the name to kb etc. Also, the nomenclature may be flawed in the first place, so it may be an opportunity to review it.

connection

Scroll to Top