多编程语言项目的命名约定
我目前正在开发一个项目,该项目包含几种不同的“编程”语言,每种语言都有自己的命名约定。应该在整个过程中使用相同的命名约定,还是应该在每种语言中使用不同的名称以具有本机外观(即不与框架的其余部分冲突)?
例如,该项目使用 MongoDB(BSON)、C#、JSON 和 Javascript。现在,我使用该层的约定来命名每一层中的事物,然后在每层之间进行代码转换,例如从 BSON 到 C# 模型。另一方面,如果命名约定相同,MongoDb 会自动执行此操作。
I am currently working on a project that incorporates several different "programming" languages, each of which have their own conventions for how things should be named. Should the same naming convention be used throughout, or should names be different in each language to have a native look (ie not clash with the rest of the framework)?
For example, ths project uses MongoDB(BSON), C#, JSON, and Javascript. Right now I name things in each layer with that layer's convention and then have code between each layer to translate, say from BSON to the C# model. On the other hand, MongoDb would do this automatically if the naming convention was the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
二十多年前,当我刚刚开始我的职业生涯时,我可能会同意保罗的观点并说“采用通用命名约定!”。 :)
今天我的答案不同了。即使您使用一种编程语言,想出一个像样的命名约定也是一项具有挑战性的任务。拥有多种语言/框架的通用约定是一个崇高的目标和出色的脑筋急转弯,但总的来说我认为这是不可行的。不同语言/框架的句法和词汇规则过于多样化,无法做到“一刀切”。此外,所使用的语言/框架集可以随时更改,并且对“通用约定”的适当调整可能会变得非常昂贵或非常不合时宜。
因此,我建议主要关注每种语言/框架(或足够相似的每组语言/框架 - 例如 C 和 C++)的可靠和体面的约定。这种方法的一个很好的结果是,仅涉及一种语言的项目必须遵守一组看起来不“陌生”的约定。
话虽如此,我相信一些约定对于所有涉及的语言/框架来说都是通用的,而不会变得太“陌生”。此外,诸如词汇之类的东西应该对于整个项目来说是通用的。当然,这主要是关于语义和词汇规则的。但即使是一些句法规则也可以是通用的。例如:
实体名称的词汇规则(例如“始终使用单数名词”)。
缩略词的词汇规则(例如“仅使用广为人知的缩略词”)。
复合名称的语法规则(例如“始终使用通用然后特定的顺序”)。
当然,上面的例子过于简单化了。但我希望这个想法是明确的:任何常见的约定都应该是常见的,但它总是只是您需要的所有约定的某个子集。
Twenty-something years ago, when I was just starting my professional career, I'd probably agree with Paul and say "Go for a universal naming conventions!". :)
Today my answer is different. Coming up with a decent naming conventions is a challenging task even when you are dealing with one programming language. Having universal conventions for multiple languages/frameworks is a noble goal and excellent brain teaser, but in general I don't think it's feasible. The syntactic and lexical rules of different languages/frameworks are way too diverse to make "one size fit all". Besides, the set of the employed languages/frameworks can change at any time, and appropriate adjustment of your "universal conventions" could turn out to be prohibitively expensive or prohibitively untimely.
So I would recommend to focus primarily on solid and decent conventions for each language/framework (or for each group of languages/frameworks that are sufficiently similar - like C and C++, for instance). One nice outcome of this approach is that the projects involving only one language would have to adhere to a set of conventions that does not look "foreign".
Having said all that, I believe that some conventions can be common for all the involved languages/frameworks without becoming too "foreign". Moreover, such thing as vocabulary should be common for entire project. This is mostly about semantic and lexical rules, of course; but even some syntactic rules can be universal, too. For example:
Lexical rules for entity names (e.g. "always use singular nouns").
Lexical rules for acronyms (e.g. "use only wide-known acronyms").
Syntactic rules for composite names (e.g. "always use general-then-specific sequence").
The examples above are oversimplified, of course. But I hope the idea is clear: whatever conventions can be common should be common, but it's always going to be just some subset of all the conventions that you need.
是的。 DOM 就是一个很好的例子:
与 SAX 一样:
或 ODBC:
Yes. The DOM would be a good example:
as would SAX:
or ODBC: