代碼規范之Variable Names變量名
golang中
官方文檔:https://go.dev/wiki/CodeReviewComments#variable-names
Variable names in Go should be short rather than long. This is especially true for local variables with limited scope. Prefer c to lineCount. Prefer i to sliceIndex.
Go語言中的變量名應該簡短而不是冗長。局部變量尤其如此,它們的范圍有限。c優于lineCount。i優于sliceIndex。
The basic rule: the further from its declaration that a name is used, the more descriptive the name must be. For a method receiver, one or two letters is sufficient. Common variables such as loop indices and readers can be a single letter (i, r). More unusual things and global variables need more descriptive names.
基本規則:**名稱使用距離其聲明越遠,名稱就必須越具有描述性。**對于方法接收器,一到兩個字母就足夠了。常見的變量,例如循環索引和讀取器,可以用單個字母(i,r)。更不常見的事物和全局變量需要更具描述性的名稱。