Section 02
Types & Variables
Go is statically typed. Types are explicit, integer sizes are explicit, and every variable has a zero value — there is no uninitialised state.
Variable declaration — four forms
☕ Java — declaration
◎ Go — four equivalent forms
Why Go does thisJava objects can be null, causing NullPointerExceptions. Go value types always have a zero value. Only pointers, slices, maps, and interfaces can be nil — and you know which ones those are because you declared them that way.
Integer types — size is explicit
go — integer types, pick intentionally
ℹ
byte and uint8 are identical — just different names expressing intent. Same for rune and int32. The name you use tells the reader what the value represents.Named types and enums with iota
☕ Java — enum
◎ Go — named type + iota
Why Go does thisGo has no enum keyword. Instead, a named type over int plus iota constants gives you the same safety. The compiler treats
Status and int as different types — you cannot accidentally pass a raw integer where a Status is expected.