Go005 Golang Keywords and Identifiers

Golang keywords

Keywords are the special words reserved for golang compiler, which help
compiler understand and parse user code. Golang has 25 keywords till now(go 1.18):

1break     default      func    interface  select
2case      defer        go      map        struct
3chan      else         goto    package    switch
4const     fallthrough  if      range      type
5continue  for          import  return     var

These keywords can be categorized to 4 group:

  1. package, import, func, const, type, var are used to declare all kinds of code
    elements in go program.
  2. chan, interface, map, struct are used when declare or use of composite type.
  3. break, case, continue, default, else, fallthrough, for, goto, if, range
    return, select, switch are used to control flow of go code.
  4. defer and go alse used to control flow of code, but they are in different
    manner, they modify the default behave of function call.

Golang Identifiers

An identifier in golang is a token which must be composed of Unicode letters,
Unicode digits (Number category Nd in Unicode Standard 8.0) and _ (underscore),
and start with either an Unicode letter or _, can’t start with an Unicode digits:

  • Unicode letters mean the characters defined in the Letter categories Lu, Ll, Lt, Lm,
    or Lo of The Unicode Standard 8.0.
  • Unicode digits mean the characters defined in the Number category Nd of
    The Unicode Standard 8.0. keywords can not be used as identifiers.

Unicode categories

All names of types, variables, constants, labels, package names and package import names
must be identifiers. An identifier start with an Unicode upper case letter(Lu) called
an exported identifier, called public in many other languages. The identifiers which
don’t start with a Lu called non-exported identifier(unexported identifier), called private
in other languages. Till go1.18, the Orient charaters are viewed as non-exported letters.

Legal exported identifiers eg:


Legal non-exported identifiers eg:


Go006 Golang Builtin Types and Value Literals