Here are some conventions I love for naming data manipulation functions.
The names are
format. Prefixes, as in:
I love these names. There are many std libs that use these names for things like dates and strings.
I like to apply these names more broadly. They can apply to more than just de/serialization.
Leave Other Names
Once we have the
format 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:
These two prefixes,
format, can be our common "data transform" naming conventions.
When To Use
So, when do we use these names? Think in terms of opposites. These are companion names.
Easiest situation: To a string:
format. From a string:
parse. But this can be used for turning any object into another object.
parse. Creating output:
format. Sometimes it's tricky, right, because every function essentially has an input and an output. So it depends on the context of usage. How do you think about the function's primary purpose, and how do you want others to think about it?
parse. Prepping request:
Most abstract rule: Beginning transform:
parse. Ending transform:
Helpful? Yes, I've found a lot of mileage in this convention.