Home >Backend Development >Golang >Share some notes on Go naming conventions

Share some notes on Go naming conventions

藏色散人
藏色散人forward
2020-08-18 11:47:152398browse

The following column will share with you some notes on Go naming conventions from the Golang Language Tutorial column. I hope it will be helpful to friends in need!

Share some notes on Go naming conventions

  • Use camelCase
  • Acronyms should be in all uppercase letters, such as ServeHTTP
  • A single letter represents the index : i, j, k
  • Short but descriptive name: cust instead of customer
  • Repeating letters to represent a collection, slice, or array, and use a single letter within the loop:
var tt []*Thingfor i, t := range tt {
  ...
}
  • Avoid duplicate package names:
log.Info()    // good
log.LogInfo() // bad
  • Don’t be like getters or setters are named like this:
custSvc.cust()    // good
custSvc.getCust() // bad
  • Add er to the interface
type Stringer interfaces {
  String() string
}

For more golang technical articles, please visit the golang tutorial column!

The above is the detailed content of Share some notes on Go naming conventions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete