Everything in Go is pass by value
- Like C, but with garbage collection, memory safety, and special mechanisms for concurrency
- Pointers but no pointer arithmetic
- No header files
- Simple, clean syntax
- Very fast native compilation (about as quick to edit code and restart as a dynamic language)
- Easy-to-distribute executables
- No implicit type coercions
- Simple built-in package system
- Simple tools
- Inferred types on variable declarations
- Slices and maps (feel like arrays and hashmaps in dynamic languages)
- Explicit error handling with error values and multiple return
- Interface-based polymorphism
- Interfaces implicitly implemented (allowing post-hoc interfaces for imported types)
- Goroutines (runtime managed lightweight threads)
- Channels for coordinating goroutines and sharing data between them (based on the theory of CSP)
int8 // 8-bit signed int
int16 // 16-bit signed int
int32 // 32-bit signed int
int64 // 64-bit signed int
uint8 // 8-bit unsigned int
uint16 // 16-bit unsigned int
uint32 // 32-bit unsigned int
uint64 // 64-bit unsigned int
float32 // 32-bit float
float64 // 64-bit float
complex64 // two 32-bit floats
complex128 // two 64-bit floats
int // 32- or 64-bit signed int (depends upon compilation target)
uint // 32- or 64-bit unsigned int (depends upon compiliation target)
uintptr // unsigned int large enough to store an address on compilation target
string // a string value is an address referencing UTF-8 data elsewhere in memory
bool
byte // alias for uint8
rune // alias for int 32 (used for representing Unicode code points)The semi-colons used in most C-like syntaxes are generally left implicit in Go. Semi-colons are implicit at the end of any line ending with:
- a number, string, or boolean literal
- an identifier
- the reserved words
break continue fallthrough return - the operators
++ -- - the end delimiters
} ] )
The full syntax for declaring a variable:
var NAME TYPE; // declare without initialization
var NAME TYPE = EXPRESSION; // declare with initialization
