Section 1 of 11
Functions & syntax
Types come after names. No void. Multiple return values.
Go moves every type to the right of the thing it describes. That single rule accounts for most of why Go looks alien to a Java reader.
func add (a, b int) int
| | | |
| | | +-- return type, AFTER the parens
| | +-- params: NAME first, TYPE second
| +-- function name
+-- keyword, alwaysFunctions, multiple returns, zero values
go.dev playground
Try it: Try removing the `_ =` on the last line — unused variables are a compile error, not a warning.
- Shorthand when types repeat: func add(a, b int) int.
- := declares and infers; var is for zero values or explicit types.
- Unused locals AND unused imports are compile errors. Deliberate, not pedantry.
- No ternary operator. No while (for does everything). No do-while.