C++核心准则边译边学

Wesley13
• 阅读 648

C++核心准则边译边学

In.not: Non-aims(目标之外)

The rules are not intended to be minimal or orthogonal. In particular, general rules can be simple, but unenforceable. Also, it is often hard to understand the implications of a general rule. More specialized rules are often easier to understand and to enforce, but without general rules, they would just be a long list of special cases. We provide rules aimed at helping novices as well as rules supporting expert use. Some rules can be completely enforced, but others are based on heuristics.

这些规则不以最小化和正交为目的。通常,普遍的规则可以简单,但不会强制。同时,理解普遍规则的含义一般也比较困难。更加特殊的规则一般更容易理解和执行。但如果没有普遍规则,规则只能是一长串特殊情况的列举。我们提示规则时即希望帮助初学者,又支持专家用途。有些规则可以完全强制执行,有些则基于启发和引导。

These rules are not meant to be read serially, like a book. You can browse through them using the links. However, their main intended use is to be targets for tools. That is, a tool looks for violations and the tool returns links to violated rules. The rules then provide reasons, examples of potential consequences of the violation, and suggested remedies.

这些规则没有要求像书一样从前往后阅读。你可以使用链接通览它们。然而,最被期待的用法是作为工具使用。也就是说,用于检查规则违反和获取被违反规则的链接的工具。这些规则可以提供原因,违反的潜在后果示例和建议的改善措施。

These guidelines are not intended to be a substitute for a tutorial treatment of C++. If you need a tutorial for some given level of experience, see the references.

这些准则没有意图成为C++入门培训的代替者。如果你需要某种层次的辅导,请参照参考资料。

This is not a guide on how to convert old C++ code to more modern code. It is meant to articulate ideas for new code in a concrete fashion. However, see the modernization section for some possible approaches to modernizing/rejuvenating/upgrading. Importantly, the rules support gradual adoption: It is typically infeasible to completely convert a large code base all at once.

这也不是一个介绍如何将旧C++代码转换为更新式的代码的指南。它是关于以具体方式生成新代码的明确想法的。然而,现代化的部分可以看做是通往现代化/年轻化/升级的可能方式。重要的是,这些规则支持循序渐进式的运用:它通常不适合一次彻底转换大量代码时使用。

These guidelines are not meant to be complete or exact in every language-technical detail. For the final word on language definition issues, including every exception to general rules and every feature, see the ISO C++ standard.

这些指南也没有意图在每个语言技术细节做到完全和彻底。关于语言定义方面的最终表达,包含普遍规则的每个例外、每个功能等,请参照ISO C++标准。

The rules are not intended to force you to write in an impoverished subset of C++. They are emphatically not meant to define a, say, Java-like subset of C++. They are not meant to define a single "one true C++" language. We value expressiveness and uncompromised performance.

这些规则没有意图强制你在C++的贫乏子集内写代码。特别是没有意图定义一个类Java的C++子集。它们也没有意图定义一个独立的“真正的C++”语言。我们重视表现力的同时不在性能上妥协。

The rules are not value-neutral. They are meant to make code simpler and more correct/safer than most existing C++ code, without loss of performance. They are meant to inhibit perfectly valid C++ code that correlates with errors, spurious complexity, and poor performance.

这些规则是有倾向性的。它们试图使代码比多数已经存在的C++代码更简单而且更正确和安全。它们希望可以禁止完全合法但是会带来错误,不必要的复杂性和不良性能的C++代码。

The rules are not precise to the point where a person (or machine) can follow them blindly. The enforcement parts try to be that, but we would rather leave a rule or a definition a bit vague and open to interpretation than specify something precisely and wrong. Sometimes, precision comes only with time and experience. Design is not (yet) a form of Math.

这些规则没有精确到一个人(或机器)可以盲目地遵从的程度。执行的部分努力做到这一点,但是我们更愿意让规则或者定义稍微含糊一些以便解释而不是过度精确的定义却导致错误。有时准确只能源自积累和经验。设计还不是数学的一种形式。

The rules are not perfect. A rule can do harm by prohibiting something that is useful in a given situation. A rule can do harm by failing to prohibit something that enables a serious error in a given situation. A rule can do a lot of harm by being vague, ambiguous, unenforceable, or by enabling every solution to a problem. It is impossible to completely meet the "do no harm" criteria. Instead, our aim is the less ambitious: "Do the most good for most programmers"; if you cannot live with a rule, object to it, ignore it, but don't water it down until it becomes meaningless. Also, suggest an improvement.

规则不是完美的。在某些特性场合,它可能会因为阻止某些有用的事情发生变得有害。在某些特定场合,规则可能因为没能阻止产生一系列错误的产生会变得有害。规则可能由于含糊,模棱两可,不可行或者产生让每个解决方案发生问题而产生很多危害。不可能存在完全无害的准则。相反,我们的目标不那么雄心勃勃:“为大多数程序做尽量好的事情”;如果你不能接纳某条规则,你可以反对它,忽略它,但不要打折扣地执行直至它变得毫无意义。你也可以提出改善建议。

本文分享自微信公众号 - 面向对象思考(OOThinkingDalian)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

点赞
收藏
评论区
推荐文章
Stella981 Stella981
3年前
Opencv中Mat矩阵相乘——点乘、dot、mul运算详解
Opencv中Mat矩阵相乘——点乘、dot、mul运算详解2016年09月02日00:00:36 \牧野(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fme.csdn.net%2Fdcrmg) 阅读数:59593
Stella981 Stella981
3年前
C# Aspose.Cells导出xlsx格式Excel,打开文件报“Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃”
报错信息:最近打开下载的Excel,会报如下错误。(xls格式不受影响)!(https://oscimg.oschina.net/oscnet/2b6f0c8d7f97368d095d9f0c96bcb36d410.png)!(https://oscimg.oschina.net/oscnet/fe1a8000d00cec3c
Stella981 Stella981
3年前
OpenCV检测轮廓极点(Python C++)
    今天分享一个OpenCV检测轮廓极点实例,原图如下,我们需要检测出地图中最大轮廓的上下左右四个极点,并进行标注显示。!(https://oscimg.oschina.net/oscnet/ae374a72c5404b00b0e976e499eedf36.png)    第一步:阈值处理分割出地图轮廓!(ht
Stella981 Stella981
3年前
Linux查看GPU信息和使用情况
1、Linux查看显卡信息:lspci|grepivga2、使用nvidiaGPU可以:lspci|grepinvidia!(https://oscimg.oschina.net/oscnet/36e7c7382fa9fe49068e7e5f8825bc67a17.png)前边的序号"00:0f.0"是显卡的代
Stella981 Stella981
3年前
KVM调整cpu和内存
一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid
Stella981 Stella981
3年前
Github标星5300+,专门为程序员开发文档开源管理系统,我粉了
!(https://oscimg.oschina.net/oscnet/a11909a041dac65b1a36b2ae8b9bcc5c432.jpg)码农那点事儿关注我们,一起学习进步!(https://oscimg.oschina.net/oscnet/f4cce1b7389cb00baaab228e455da78d0
Stella981 Stella981
3年前
Nginx反向代理upstream模块介绍
!(https://oscimg.oschina.net/oscnet/1e67c46e359a4d6c8f36b590a372961f.gif)!(https://oscimg.oschina.net/oscnet/819eda5e7de54c23b54b04cfc00d3206.jpg)1.Nginx反
Wesley13 Wesley13
3年前
1024程序猿节,聊聊石头学了哪些课,屯了哪些书?
!(https://oscimg.oschina.net/oscnet/317debacc36e4ab6ba47c12337d02533.gif)点击上方蓝色字体,关注我——一个在阿里云打工的清华学渣!!(https://oscimg.oschina.net/oscnet/7046a0e5c
Wesley13 Wesley13
3年前
C++核心准则编译边学
!(https://oscimg.oschina.net/oscnet/713eb5c59e184a289ae775269e3c170a.jpg)F.46:intisthereturntypeformain()F.46:main函数的返回值类型是整数Reason
Stella981 Stella981
3年前
Flink SQL Window源码全解析
!(https://oscimg.oschina.net/oscnet/72793fbade36fc18d649681ebaeee4cdf00.jpg)(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fmp.weixin.qq.com%2Fs%3F__biz%3DMzU3MzgwNT