为何命名空间? [英] Why namespaces?

查看:58
本文介绍了为何命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一家小公司工作,开发人员不喜欢使用新

功能,当他们发现旧功能足够时。例如如果在类和名称空间之间选择了
,他们会选择类。给定选择

在全局范围内的命名函数与子系统前缀

(例如CTNode,CPNode)与名称空间(Time :: Node,Place :: Node)之间我们'll

使用全局命名空间。他们理解的前缀,前缀是短的,并且可以完成工作。命名空间需要更多的输入。


我们理解为什么命名空间对库开发人员有好处:我们可以

避免名称冲突。但是对我们自身发展的好处不那么明显了。


所以这里是我的问题:


使用命名空间与使用子系统

前缀是否有任何好处?具体来说,编译器和链接器运行速度是否可以更快?

带名称空间?

Stuart

I work in a small company with developers who do not like to use "new"
features when they find the old ones sufficient. e.g. given a choice
between a class and a namespace, they''ll pick class. Given a choice
between naming functions at the global scope with subsystem prefixes
(e.g. CTNode, CPNode) vs. namespaces (Time::Node, Place::Node) we''ll
use the global namespace. Prefixes they understand, and prefixes are
short and do the job. Namespaces require more typing.

We understand why namespaces are good for library developers: we can
avoid name clashes. But the benefits for our own development are less
clear to me.

So here''s my question:

Is there any advantage to using namespaces vs. using subsystem
prefixes? And specifically, can the compiler and linker run faster
with namespaces?

Stuart

推荐答案



" Stuart" < sj*@igs.net>在消息中写道

news:11 ********************** @ g47g2000cwa.googlegr oups.com ...

"Stuart" <sj*@igs.net> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
我在一家小公司工作,开发人员不喜欢使用新功能,当他们发现旧功能足够时。例如在类和命名空间之间进行选择时,他们会选择课程。给定全局范围内的命名函数与子系统前缀(例如CTNode,CPNode)与命名空间(Time :: Node,Place :: Node)之间的选择我们将使用
全局命名空间。他们理解前缀,前缀很短,可以完成工作。命名空间需要更多的输入。

我们理解为什么命名空间对库开发人员有好处:我们可以避免名称冲突。但是我自己开发的好处对我来说不太清楚。

所以这里是我的问题:

使用名称空间对比是否有任何优势使用子系统
前缀?具体来说,编译器和链接器可以更快地运行命名空间吗?

Stuart
I work in a small company with developers who do not like to use "new"
features when they find the old ones sufficient. e.g. given a choice
between a class and a namespace, they''ll pick class. Given a choice
between naming functions at the global scope with subsystem prefixes
(e.g. CTNode, CPNode) vs. namespaces (Time::Node, Place::Node) we''ll
use the global namespace. Prefixes they understand, and prefixes are
short and do the job. Namespaces require more typing.

We understand why namespaces are good for library developers: we can
avoid name clashes. But the benefits for our own development are less
clear to me.

So here''s my question:

Is there any advantage to using namespaces vs. using subsystem
prefixes? And specifically, can the compiler and linker run faster
with namespaces?

Stuart




嗯,你很自由使用你想要的任何方法。但我几乎看不到

" CTNode"作为提供信息。 C是什么?和T代表?一个

必须提前知道。另外,有一天你可能会发现你的首字母缩写词没有结果,因为你发现需要一个C。前缀代表什么

else!


如果您的编码实践以减少打字为指导,那么您正在工作

根据与完成任务几乎没有关系的规则。设计精良的程序应该花费更多的时间在设计上而不是在

编码中,所以节省一些按键不应该影响整个开发时间

显着。 (此外,您可以随时将使用命名空间时间;

放在任何需要的地方,并为自己节省一些打字。)


甚至使用你的前缀编码风格,我希望我的编码人员使用类似TimeNode而不是TNode的
,所以每个人都知道什么是b,b是什么。代表。击键被击败......我想知道我在做什么

,而不是四处寻找手册或询问其他程序员什么是

'' T'代表什么?


我的价值2美分(不含税和小费)。


-Howard



Well, you''re quite free to use whatever method you desire. But I hardly see
"CTNode" as being informative. What do the "C" and the "T" stand for? One
has to know in advance. Plus, some day you may find that your acronym fails
you, because you find the need for a "C" prefix which stands for something
else!

If your coding practices are guided by "less typing", then you''re working
under rules that have little to do with accomplishing the task. A
well-designed program should have MUCH more time spent in designing than in
coding, so saving a few keystrokes shouldn''t impact overall devlopment time
significantly. (Besides, you can always put "using namespace Time;"
wherever you need it, and save yourself some typing.)

And even using your "prefix" coding style, I''d want my coders to use
something like TimeNode instead of TNode, so everyone knows what the heck
the "T" stands for. Keystrokes be damned...I want to know what I''m working
with, not run around looking in manuals or asking other coders "what does
''T'' stand for?"

Just my 2 cents worth (tax and tip not included).

-Howard


我稍微缩写了前缀 - 但只有一点。这个项目很好地组织起来了。
组织得很好。我们有几个主要的子系统:U。实用工具,

DB对于数据库等。我们没有缺少

前缀的风险。在开发

环境中清楚地组织文件和类,因此使用子系统名称更明确清楚

没有太大的好处:TA,基于

的上下文,QP等足够清楚。我们的班级名称和方法名称通常很长

足以清楚。


因此,使用您的命名示例,使用该名称有什么好处?

时间::节点

而不是

TimeNode?


Stuart

I abbreviated the prefixes a bit - but only a bit. The project is
nicely organized. We have a few major subsystems: "U" for utility,
"DB" for database, and the like. We have no risk of running short of
prefixes. Files and classes are organized clearly in the development
environment, so there''s no huge benefit to being more explicitly clear
with the subsystem name: "TA", "QP", etc. are clear enough based on
the context. Our class names and method names are typically long
enough to be clear.

So using your naming example, what''s the benefit of using the name
Time::Node
instead of
TimeNode?

Stuart


你应该避免使用非常通用的名称,例如''connect''或''date''

你的类以避免名字与最终的第三次冲突派对libs,

帮助你这个命名空间可能是有益的。

You should avoid very generic names like '' connect'' or '' date'' for
your classes to avoid name clashes with eventual third party libs, to
help you with this a namespace can be beneficial.


这篇关于为何命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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