A simplified explanation of the difference between identifiers, expressions and statements is,
- identifiers are names of things
- expressions are things that have values (you can pass these into functions), or refer to types
- statements are instructions to do things
Consider the following snippet.
var bar Bar
if err := foo(bar.Baz()); err != nil {
return err
}
It contains,
-
identifiers:
err
,foo
,bar
,Bar
,Baz
var bar Bar '-' '-' if err := foo(bar.Baz()); err != nil { '-' '-' '-' '-' '-' return err '-' }
-
expressions:
Bar
,bar.Baz
,bar.Baz()
,foo(bar.Baz())
,err
,nil
, anderr != nil
var bar Bar '-' .-------. .---|-------|. .---------. if err := foo(bar.Baz()); err != nil { '-' | '-' '-' '-----' return err '-' }
Note that
bar
invar bar Bar
is not an expression. -
statements:
var ...
,err := ...
,if ...
, andreturn ...
var bar Bar '---------' if err := foo(bar.Baz()); err != nil { -. '-------------------' | return err | '--------' | } -'