普遍事项重载vs模板vs程序 [英] An Ecumenical Matter Overloaded vs template vs procedural

查看:62
本文介绍了普遍事项重载vs模板vs程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我对效率有一个普遍的问题.

考虑一个用于检查表上是否存在特定值的函数.

当前,每个表都有自己的表,并按键类型重载.

但是最终系统中会有许多非常相似的功能.

因此,它们成为共享库中单个模板功能的理想候选者.

或单个常规检查功能:

Good day all,

I have an ecumenical question on effeciency.

Consider a function to check if a specific value exists on a table.

Currently each table has its own, overloaded by key type.

But there will be a number of very similar fuctions in the final system.

So that makes them ideal candidates for a single template function in a shared library.

Or a single conventional check function:

check(String^ ArgTable, String^ ArgKeyName, Object^ ArgKeyValue)



随后将查询ArgKeyValue以确定其类型.

就可读性和最少的代码行而言,这第三个选项看起来是最干净的,而第一个选项在一定距离内生成的代码最多.

但是,哪种解决方案在运行时效果最好?



ArgKeyValue is subesequently interrogated to determine its type.

This third option looks like the cleanest in terms of readabilty and fewest lines of code,while the first generated the most code by some distance.

But which solution will perform best at run time?

推荐答案

我认为第二种解决方案.

The second one, in my opinion.

Ger Hayden写道:
Ger Hayden wrote:

就可读性和最少的代码行而言,这第三个选项看起来是最干净的

This third option looks like the cleanest in terms of readabilty and fewest lines of code


我不这么认为(只需考虑ArgKeyValue上的大开关"即可).

:-)


I don''t think so (just think about the ''great switch'' on ArgKeyValue).

:-)


不仅您的选项没有正确解释;但是很明显,这个问题是不正确的.术语最佳"表示(部分)排序关系在选项集上定义.不,您没有定义它.您的问题看起来像:汽车A的燃油经济性更好,但是汽车B的间隙更高.哪一个最好?

—SA
Not only your options are not explained properly; but it is clear that the question is incorrect. The term "best" suggests that the relationship of (partial) ordering is defined on the set of option. No, you don''t define it. Your question looks like: the car A has better fuel economy, but the car B has higher clearance. Which one is the best?

—SA


这篇关于普遍事项重载vs模板vs程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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