欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C++核心准则边译边学-P.13: 酌情使用支持库

程序员文章站 2024-03-18 08:46:16
...

P.13: Use support libraries as appropriate(酌情使用支持库)

Reason(原因)

Using a well-designed, well-documented, and well-supported library saves time and effort; its quality and documentation are likely to be greater than what you could do if the majority of your time must be spent on an implementation. The cost (time, effort, money, etc.) of a library can be shared over many users. A widely used library is more likely to be kept up-to-date and ported to new systems than an individual application. Knowledge of a widely-used library can save time on other/future projects. So, if a suitable library exists for your application domain, use it.

使用经过良好设计,良好文档化,良好支持的功能库既可以省时,又可以省力。即使你花费主要精力去实现某项功能,支持库的品质和文档还是有很大的可能性会会比你做的好。支持库的成本(时间,劳力,费用等)可以被很多用户分担。一个广泛使用的支持库比单独的应用更有可能保持最新状态并且使用到新系统。(在一个项目上获得的)有关广泛使用的支持库的知识可以使我们在另外/将来的项目上节约时间。因此,如果在和你的应用领域中存在合适的支持库,就使用它。

Example(示例)

 

std::sort(begin(v), end(v), std::greater<>());

Unless you are an expert in sorting algorithms and have plenty of time, this is more likely to be correct and to run faster than anything you write for a specific application. You need a reason not to use the standard library (or whatever foundational libraries your application uses) rather than a reason to use it.

除非你是一个排序算法方面的专家而且有大量的时间,这段代码非常有可能比你针对特殊应用编写的任何代码都要正确并且执行地更快。

Note(注意)

By default use(缺省条件下使用)

  • The ISO C++ Standard Library(ISO C++标准库)
  • The Guidelines Support Library(准则支持库)

Note(注意)

If no well-designed, well-documented, and well-supported library exists for an important domain, maybe you should design and implement it, and then use it.

如果在一个重要的领域中,不存在经过良好设计,良好文档化和良好支持的功能库,可能你应该设计、实现一个并使用它。

 

觉得本文有帮助,欢迎点赞并分享给更多的朋友!

阅读更多更新文章,请关注微信公众号【面向对象思考】