Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 356
foraidt Avatar asked Aug 06 '09 11:08

foraidt


1 Answers

How about GetOrCreate()

like image 124
Sean Avatar answered Sep 28 '22 12:09

Sean