SL.1: Use libraries wherever possible

SL.1:在任何可能的情况下使用已有库

 

Reason(原因)

Save time. Don't re-invent the wheel. Don't replicate the work of others. Benefit from other people's work when they make improvements. Help other people when you make improvements.

节约时间。不要重新发明车轮。不要重复其他人的工作。如果其他人进行了某种改善,我们可以从中获益。如果你进行了某种改善,帮助其他人获益。

 

SL.2: Prefer the standard library to other libraries

SL.2:标准库好于其他库

 

Reason(原因)

More people know the standard library. It is more likely to be stable, well-maintained, and widely available than your own code or most other libraries.

更多人知道标准库。标准库更有可能维持稳定,被很好地维护,比你自己写的代码或其他库具有更广泛的可用性。

 

SL.3: Do not add non-standard entities to namespace std

SL.3:不用选项std命名空间增加非标准实体

 

Reason(原因)

Adding to std might change the meaning of otherwise standards conforming code. Additions to std might clash with future versions of the standard.

将实体添加到std命名空间可能会改变其他遵守标准的代码的含义。增加到std命名空间中的实体有可能和标准库的将来版本发生冲突。

 

Example(示例)

???

 

Enforcement(实施建议)

Possible, but messy and likely to cause problems with platforms.

有可能,但是会混乱并可能引起平台相关问题。

 

SL.4: Use the standard library in a type-safe manner

SL.4:以类型安全的方式使用标准库

 

Reason(原因)

Because, obviously, breaking this rule can lead to undefined behavior, memory corruption, and all kinds of other bad errors.

因为,很显然,破坏这条规则会引发无定义行为,内存破坏或者各种其他类型的恶劣问题。

 

Note(注意)

This is a semi-philosophical meta-rule, which needs many supporting concrete rules. We need it as an umbrella for the more specific rules.

这是一条半哲学性质的准则,它需要很多具体准则的支持。我们需要将本规则当作其它具体规则的整体概括来看。

Summary of more specific rules:

更特定规则的归纳:

  • SL.4: Use the standard library in a type-safe manner
  • SL.4: 以类型安全的方式使用标准库

 

原文链接

​https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#sl1--use-libraries-wherever-possible​

 

新书介绍

​《实战Python设计模式》​​是作者最近出版的新书,拜托多多关注!

C++核心准则:积极、正确地使用标准库_标准库

本书利用Python 的标准GUI 工具包tkinter,通过可执行的示例对23 个设计模式逐个进行说明。这样一方面可以使读者了解真实的软件开发工作中每个设计模式的运用场景和想要解决的问题;另一方面通过对这些问题的解决过程进行说明,让读者明白在编写代码时如何判断使用设计模式的利弊,并合理运用设计模式。

对设计模式感兴趣而且希望随学随用的读者通过本书可以快速跨越从理解到运用的门槛;希望学习Python GUI 编程的读者可以将本书中的示例作为设计和开发的参考;使用Python 语言进行图像分析、数据处理工作的读者可以直接以本书中的示例为基础,迅速构建自己的系统架构。

 


 

觉得本文有帮助?请分享给更多人。

关注微信公众号【面向对象思考】轻松学习每一天!

面向对象开发,面向对象思考!

 

C++核心准则:积极、正确地使用标准库_python_02