Search code examples
language-agnosticfunctioncoding-stylenaming

Function name for creating something if it's not there yet


From time to time I write a function that just creates something if it's not there yet and otherwise does nothing.
Names like CreateFooIfNecessary() or EnsureThereIsAFoo() do work but they feel a bit clumsy.

One could also say GetFoo() but that name doesn't really imply that foo may be created first and it only works if the function returns a handle/pointer/reference to foo.

Can those of you more familiar with the English language come up with a better way to name these functions?


Solution

  • How about GetOrCreate()