Golang naming convention

Time:2021-11-28

All naming of function name, variable name, constant name, type name, statement label and package name in go language follow a simple naming rule.

It must start with a letter or underscore (), followed by any number of letters, numbers or underscores.

In the go language, upper and lower case letters are different.

There are 25 keywords in go language, which cannot be used for custom names:

break        default      func         interface    select
case         defer        go           map          struct
chan         else         goto         package      switch
const        fallthrough  if           range        type
continue     for          import       return       var
  • Variables can only be composed of letters, numbers and underscores.
  • Cannot start with a number.
  • Cannot be a keyword or reserved word in go
  • Case sensitive,a := 1andA := 1Are two variables.

The above requirements must be met, and the following requirements should be met as much as possible

  • Variable names should be descriptive, concise and easy to read, and should not be too long.
  • Proper nouns are usually capitalized, such as escape HTML.
  • Short names are preferred for local variables (I instead of index).
  • Variable names cannot be in Chinese or Pinyin.
  • Recommended variable names:
    • Hump body:MyName := "Conan"ormyName := "Conan"

37 reserved words in go language:

Constants:    true  false  iota  nil
    Types:    int  int8  int16  int32  int64
			  uint  uint8  uint16  uint32  uint64  uintptr
			  float32  float64  complex128  complex64
			  bool  byte  rune  string  error
Functions:    make  len  cap  new  append  copy  close  delete
			  complex  real  imag
			  panic  recover

Li peiguan blog

lpgit.com

Recommended Today

On the mutation mechanism of Clickhouse (with source code analysis)

Recently studied a bit of CH code.I found an interesting word, mutation.The word Google has the meaning of mutation, but more relevant articles translate this as “revision”. The previous article analyzed background_ pool_ Size parameter.This parameter is related to the background asynchronous worker pool merge.The asynchronous merge and mutation work in Clickhouse kernel is completed […]