Array types
Arrays have fixed length as part of their type and use value semantics; they are not just slices with different syntax.
Canonical guidance
[4]byteand[8]byteare different types- arrays copy on assignment and parameter passing
- slices are usually the better API surface unless fixed length matters
Use when
- reasoning about hashes, protocol fields, or fixed-size buffers
- explaining array comparability
- checking why an assignment or call does not type-check
Avoid
- exposing large arrays in ordinary APIs by accident
- assuming an array argument behaves like a slice view
- confusing
[N]Twith[]T
Preferred pattern
type Digest [32]byte
Anti-pattern
- accepting a large array by value when the function only needs a slice view
Explanation: This is tempting because the syntax is simple, but it can copy far more data than intended and make APIs awkward to use.
Why
- array semantics explain a surprising number of type mismatches around fixed-size data