Function Grouping and Ordering
- Functions should be sorted in rough call order.
- Functions in a file should be grouped by receiver.
Therefore, exported functions should appear first in a file, after
struct
,const
,var
definitions.
A newXYZ()
/NewXYZ()
may appear after the type is defined, but before therest of the methods on the receiver.
Since functions are grouped by receiver, plain utility functions should appeartowards the end of the file.
Bad | Good |
---|---|
|
|