Declaration Syntax

Go’s declaration syntax differs from C-style languages (where the type is on the left). This design choice was made to improve clarity, especially in complex function signatures.

Left-to-Right Reading

Go’s declarations are designed to be read like English, from left to right.

x int        // x is an int
p *int       // p is a pointer to an int
a [3]int     // a is an array of 3 ints

Complex Signatures

In C, complex function pointers can become almost unreadable. In Go, even complicated signatures remain relatively clear because the “what it is” (the name) comes before the “how it’s built” (the type).

// A function that takes another function and an int, returning an int
f func(func(int, int) int, int) int