Skip to content

Function Naming

Borrowed from kettanaito’s naming cheatsheet and slightly enhanced.

  • Use the A/HC/LC pattern
prefix? + action (A) + high context (HC) + low context? (LC)
NamePrefixAction (A)High context (HC)Low context (LC)
getUsergetUser
getUserMessagesgetUserMessages
handleClickOutsidehandleClickOutside
shouldDisplayMessageshouldDisplayMessage
ActionUsage
getAccesses data immediately (i.e. shorthand getter of internal data). Or async data - get a resource from the server.
setSet a variable or state to a new value.
resetSets a variable back to its initial value or state.
removeRemoves something from somewhere. E.g. remove a filter from a collection of selected filters. (opposite of add)
deleteErase something. E.g. delete resource from a database. (opposite of create)
composeCombine multiple functions or elements into one.
handleRespond to an event or trigger, typically prefixed for event callbacks (e.g. handleClick).
addInclude something in a collection or group.
createMake a new resource, object, or data structure.
formatConvert data into a specific or human-readable format.
updateChange an existing value, state, or record with new information.
initPerform initial setup or bootstrapping.
toggleFlip between two states, usually boolean (e.g. show/hide, true/false).
validateEnsure data meets required rules or structure.
transformConvert data from one shape, structure, or format to another.
cancelAbort an operation or undo a pending action.