This article will introduce keywords and identifiers in Go.
Keywords are the special words which help compilers to understand and parse user code.Up to now (Go 1.10), Go has only 25 keywords:
They can be categorized as four groups:
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
varare used to declare all kinds of code elements in Go programs.
structare used as parts in some composite type denotations.
switchare used to control flow of code.
goare also control flow keywords, but in other specific manners. They modify function calls, which we'll talk about in this article.
These keywords will be explained in details in other articles.
_(underscore) and start with either an Unicode letter or
_ is a special identifier, it is called blank identifier.
Later we will learn that all names of types, variables, constants, labels, package names and package import names must be identifiers.
An identifier starting with an Unicode upper case letter is called an exported identifier. The word exported can be interpreted as public in many other languages.
Currently (Go 1.10), eastern characters are viewed as non-exported letters. Non-exported identifiers are also called unexported or private identifiers in many documentations.
Here are some legal non-exported identifiers:
Player_9 DoSomething VERSION Ĝo Ⲡ
And here are some tokens which are illegal to be used as identifiers:
_ _status memStat book π 一个类型 변수 エラー
// Starting with a Unicode digit. 123 3apples // Containing illegal Unicode characters. a.b *ptr $name email@example.com // These are keywords. type range