Junior
Naming conventions in Go — how should abbreviations be written?
sobes.tech AI
Answer from AI
In Go, it is customary to write abbreviations in names while preserving the case of each letter of the abbreviation if it consists of two or more letters, and the abbreviation is a separate word or part of a name.
For example:
HTTPServer— the abbreviation HTTP is written in uppercase.userID— ID is written in uppercase.XmlParser— not recommended, betterXMLParser.
Rules:
- Abbreviations of two or more letters are written entirely in uppercase if they are at the beginning or middle of the name.
- If the abbreviation is at the end of the name, it is also written in uppercase.
Example:
func ServeHTTP() {}
var userID int
const maxCPU = 4
Thus, the naming style in Go is oriented towards readability and maintaining the recognizability of abbreviations.