3 ms·
For better or worse, it's convention to use really short (as in, single character when possible) variable names in Go. https://github.com/golang/go/wiki/CodeRe
by jpatokal 8y ago
For better or worse, it's convention to use really short (as in, single character when possible) variable names in Go.
https://github.com/golang/go/wiki/CodeReviewComments#variable-names https://github.com/golang/go/wiki/CodeReviewComments#variabl...
Disclaimer: I work at Google, but not on GCF or Go.
- pjmlp 8y agoI guess I forgot about those "best practices". Thanks for the heads up.
- chrisbroadfoot 8y agoI don't think "Variable names in Go should be short rather than long" is an accurate description of best practice. The wiki should probably be changed. The second paragraph there is more in line with best practice... "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." In the case of a Cloud Function, a short name like "F" is probably fine. While it needs to be exported to get deployed properly, it isn't a library function, is very unlikely to be imported by other packages, so it's really more like "func main" than anything. Most people will have a single Cloud Function in a package, and I don't think you'd reasonably have f/f.go with a function named "F".
- abtinf 8y agoAlso, in this case, the “f(w, r)” pattern is pervasive in Go web code. Anyone who has written web code in Go will instantly understand what it means and how to use it.