C.162: Overload operations that are roughly equivalent
C.162:将大致相同的操作设计为重载函数
Reason(原因)
Having different names for logically equivalent operations on different argument types is confusing, leads to encoding type information in function names, and inhibits generic programming.
逻辑上等价,只是参数不同的操作具有不同的名称是难以理解的,会导致函数名中包含类型信息,而且阻碍编程共通化。
Example(示例)
Consider(考虑下面的代码):
These three functions all print their arguments (appropriately). Conversely:
这三个函数都(恰当地)打印参数指定的内容。相反地,
These three functions all print their arguments (appropriately). Adding to the name just introduced verbosity and inhibits generic code.
这三个函数都(恰当地)打印参数指定的内容。只是在函数名中增加了冗长的,阻碍共通化编程的信息。
Enforcement(实施建议)
???
原文链接:
觉得本文有帮助?欢迎点赞并分享给更多的人。
阅读更多更新文章,请关注微信公众号【面向对象思考】