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

查看:217
本文介绍了有效C ++“。最小化文件之间的编译依赖性“。它今天仍然有效吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本章中,Scott Meyer提到了一些避免头文件依赖的技术。

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.

我的问题是:


  • 在我以前的项目中,我从来没有注意到这个规则。编译时间不短,但不是不能容忍。它可能与我的项目的规模(或缺乏)有关。

  • 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)

我使用的是第二版。

推荐答案

我不认为编译器技术有进步。 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 ++“。最小化文件之间的编译依赖性“。它今天仍然有效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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