Share some notes on Go naming conventions

藏色散人
Release: 2020-08-18 11:47:52
forward
2328 people have browsed it

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 {
  ...
}
Copy after login
  • Avoid duplicate package names:
log.Info()    // good
log.LogInfo() // bad
Copy after login
  • Don’t be like getters or setters are named like this:
custSvc.cust()    // good
custSvc.getCust() // bad
Copy after login
  • Add er to the interface
type Stringer interfaces {
  String() string
}
Copy after login

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!