notexOPENOverview
Notex/Languages/Code Review: Function values and closures
03.12LESSON 12 OF 18 · 1 MIN READ

Code Review: Function values and closures

Always free to read
  • 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.Compare and cmp.Or when writing comparator functions.

Progress is saved on this device.
KEEP EXPLORING

One note leads to another.

Back to the library →
⌕
Search across the entire library ⌘ K