有效的 C++“35.最小化文件之间的编译依赖性".今天还有效吗? [英] Effective C++ "35. Minimize compilation dependencies between files". Is it still valid today?

查看:19
本文介绍了有效的 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.最小化文件之间的编译依赖性".今天还有效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆