创建某物的函数名称(如果尚未创建) [英] Function name for creating something if it's not there yet
问题描述
有时候,我写一个函数,只是创建的东西,如果它还没有,否则什么都不做。
命名为 CreateFooIfNecessary()
或 EnsureThereIsAFoo()
做工作,但他们感到有点笨拙。
还可以说 GetFoo()
,但该名称并不意味着可以先创建foo
,并且只有当函数返回 foo
的句柄/指针/引用时才有效。
你可以更熟悉英语的人有更好的方法来命名这些函数吗?
GetOrCreate()
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?
How about GetOrCreate()
这篇关于创建某物的函数名称(如果尚未创建)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!