HomeSectionsAboutMerch
« Nouns

Common verbs for function / method names

Naming things is hard. Below is a list of verbs that can be used as names for either functions or class methods with descriptions of how they commonly behave. The list should be considered more what you'd call guidelines than actual rules.

Good names

Name Description See also
See also release
Asks to be given control over some resource in a computer. E.g. database lock, large amount of memory.Acquire/release differ from open/close in that acquire/release typically indicate that the underlying resource has a limit of how many times it can be opened at once, whereas for open/close the underlying resource can (theoretically) be opened as many times as needed at once. release
See also open
Tell the operating system that you have finished using a resource in the computer, and that any pending commands sent to that resource should be finalised. e.g. any pending writes should be written to a file. open
Creates a object from the data passed in. Usually returns an object rather than storing it internally. May throw an exception if the data does not meet some required conditions (e.g. is invalid).
See also execute
execute
See also dispatch
dispatch
Attempts to locate a piece of data from a containing storage type. If the containing storage does not contain any data by the name parameter, very likely to return null.
See also set
Returns a value from the class/data being operated on. No 'get' method should do heavy calculations or throw exception. Or gets a value from a containing storage type set
See also has
Takes a key as a parameter and returns a value from a container (e.g. array, map) corresponding to that key. Generally throws an exception if the container does contain a value corresponding to that key. has
has
Checks whether a value is available from a containing storage type e.g. does an array contain a key with a particular name. Almost always returns a boolean.
See also close
Ask the operating system to open a resource in the computer. This operation may fail, and the returned value needs to be checked to be valid. close
pop
See also push
Take an item from a container e.g. array, list, queue, or stack. push
See also pop
Add an item into a container e.g. array, list, queue, or stack. pop
See also acquire
Release control over a resource given from a call to a acquire.Acquire/release differ from open/close in that acquire/release typically indicate that the underlying resource has a limit of how many times it can be opened at once, whereas for open/close the underlying resource can (theoretically) be opened as many times as needed at once. acquire
See also acquire
Reset and object back to some initial state ready to be re-used. acquire
set
See also get
Set a property of an object, or a global variable. No 'set' method should do heavy calculations. If the value being set is invalid, the function might throw an exception. get
to
See also get
Convert an object from one type to another. e.g. 'toArray', 'toJson'. Generally would not take any parameters, but might if there was some option on how the formatting is to be done. get
Return a copy of the original object, with one or more properties changed e.g. `$user.withFirstName("John")`

Bad names

Maybe we should have a list of bad names here e.g. 'make'... is that 'create' or is it 'execute'?