Map Naming Convention
Here is a convention I love for naming data manipulation functions
The prefix
The prefix I love to use in function names is map
, as in mapAThing
.
"Map" means to go from one data format or shape to another.
When naming the entire function, use map
as the prefix and then the noun of what your mapping to (ie, the output). For example, if I'm making a list of links, use it as Enum.map(input_list, map_link)
. Or if I need to transform a model to a view model, mapViewModel(model)
Leave other names
Once we have the map
convention, we can leave so many others behind and be more consistent. Without these, we might have a clutter of similar-meaning but different-sounding names.
get
- reserve for straight access, no transformation. But, really, avoid; just use data.
find
- reserve only for return one of many things, based on a predicate.
fetch
- reserve for data source access only.
create
- reserve for data persistence only.
parse
and format
- use only for string de/serialization.
Abandon: determine
, build
, gen/generate
, make
, transform
, wrap
.
Helpful? Yes, I've found a lot of mileage in this convention.