-
If multiple functions with the same signature are used for similar purposes and assigned to variables, define a function type and use it when declaring the function variables. This clarifies the relationship between the functions and documents their purpose.
-
Take care when using package-level function variables. Unlike function declarations, they are mutable, which means their functionality can be changed at runtime.
-
If you have a helper function that’s only used within a single function, consider using a closure for the helper function.
-
Use function parameters to “plug in” logic to a larger algorithm, such as to specify the sort order when sorting a slice.
-
Default to using
cmp.Compareandcmp.Orwhen writing comparator functions.
Progress is saved on this device.