Effective C++ quot;35. Minimize compilation dependencies between filesquot;. Is it still valid today?(有效的 C++“35.最小化文件之间的编译依赖性.今天还有效吗?)
问题描述
在这一章中,Scott Meyer 提到了一些避免头文件依赖的技术.如果更改仅限于其他包含的头文件,主要目标是避免重新编译 cpp 文件.
In this chapter Scott Meyer mentioned a few technique to avoid header files dependency. The main goal is to avoid recompiling a cpp file if changes are limited to other included header files.
我的问题是:
在我过去的项目中,我从未关注过这条规则.编译时间不短但也不是不能忍受.这可能与我的项目的规模(或缺乏)有关.鉴于编译器技术(例如 clang)的进步,今天这个技巧有多实用?
In my past projects I never paid attention to this rule. The compilation time is not short but it is not intolerable. It could have more to do with the scale (or the lack of) of my projects. How practical is this tip today given the advance in the compiler technology (e.g. clang)?
在哪里可以找到更多使用此技术的示例?(例如 Gnome 或其他 OSS 项目)
Where can I find more examples of the use of this techniques? (e.g. Gnome or other OSS projects)
附:我正在使用第 2 版.
P.S. I am using the 2nd edition.
推荐答案
我不认为编译器技术特别先进.clang 并不是什么神奇的东西——如果你有依赖然后你做了改变,那么依赖的代码将不得不重新编译.这可能需要非常非常长的时间——阅读一个大项目需要几个小时甚至几天,因此人们会尽可能减少这种依赖关系.
I don't think compiler technology has advanced particularly. clang is not some piece of magic - if you have dependencies then and you make changes, then dependent code will have to be recompiled. This can take a very, very long time - read hours, or even days for a big project, so people try to minimise such dependencies where possible.
话虽如此,有可能做的太多了——将所有类都变成 PIMPL,向前声明所有内容等.这样做只会导致代码混淆,应尽可能避免.
Having said that, it is possible to overdo things - making all classes into PIMPLs, forward declaring everything, etc. Doing this just leads to obfuscated code, and should be avoided whenever possible.
这篇关于有效的 C++“35.最小化文件之间的编译依赖性".今天还有效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:有效的 C++“35.最小化文件之间的编译依赖性".今天还有效吗?
基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 初始化列表*参数*评估顺序 2021-01-01
