创建某物的函数名称(如果尚未创建) [英] Function name for creating something if it's not there yet

查看:124
本文介绍了创建某物的函数名称(如果尚未创建)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,我写一个函数,只是创建的东西,如果它还没有,否则什么都不做。

命名为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆