以不同方式提供链接的函数的命名建议
我编写了一个实验函数,该函数通过使用高阶函数使传递的对象可链接。现在它的名字是“chain”,这是一个使用示例;
chain("Hello World")
(print) // evaluates print function by passing "Hello World" object.
(console.log,"Optional","Parameters")
(returnfrom) // returns "Hello World"
它看起来很 lispy,但行为却非常不同,因为它是用基于 C 的语言编码的,我不知道这个习惯用法是否有一个名称,而且我找不到比“链”更合适的名称。
有什么想法、建议吗?
编辑:“with”听起来非常合适的名字,但它是我正在使用的语言中的保留词。
I've coded an experimental function which makes passed objects chainable by using high order functions. It's name is "chain" for now, and here is a usage example;
chain("Hello World")
(print) // evaluates print function by passing "Hello World" object.
(console.log,"Optional","Parameters")
(returnfrom) // returns "Hello World"
It looks lispy but behaves very different since it's coded in a C based language, I don't know if there is a name for this idiom and I couldn't any name more suitable than "chain".
Any ideas, suggestions?
edit: "with" sounds very suitable name but it's a reserved word in the language I'm working on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这种 API 设计模式通常称为Fluent 界面。
更新: 流畅接口的实际实现是否采用面向对象语言是无关紧要的。这是传递上下文以实现“代码流”感觉的模式,这似乎正是您想要做的。
当然,模式名称实际上并不能回答您的问题。 :-)
正如您所指出的,命名实际函数的最佳选择是
with
。第二好的方法是使用
。This API design pattern is usually called a Fluent interface.
Update: Whether the actual implementation of a fluent interface is in object-oriented language is irrelevant. It's the pattern of passing a context to achieve the feeling of a "code flow", which seems exactly what you are aiming to do.
Of course, what the pattern name is does not actually answer your question. :-)
As you noted, the best choice for naming your actual function would be
with
. Second best would beusing
.