What are the disadvantages of single source project structures?

I am new to my current company and am working on a project written by my direct management. The company usually does not work with C ++, but there is productive code written by my colleague in C / C ++. It is only we who know how to code in C ++ (me and my manual, so there is no third opinion that can be involved).

After I got a good idea about the project, I realized that the whole structure ... is special.

In fact, this consists of a single compilation unit in which the makefile only lists the source main.hpp .

This header file then includes all the source files that the project has been disabled, so it looks like a really big list:

 #include "foo.cpp" #include "bar.cpp" 

Trying to understand the logic behind it, I realized that this really works for this project, since it is just an interface in which each unit can work without access to any other unit. At some point, I asked him why he did it this way.

I got a defensive reaction with an argument

Well, it works, right? You can do it your own way if you think that is best for you.

And this is what I am doing now, simply because I really have problems with thinking in this structure. Therefore, at the moment I am applying the β€œnormal” structure to the implementation, which I am writing right now, making only the necessary changes for the entire project, to demonstrate how I would develop it.

I think that there are many shortcomings, starting with mixing linkers and compilers with the help of our own project structure, that cannot serve well, up to optimizations that probably end up with redundant or obscure results, not to mention that a clean build project takes ~ 30 minutes, which, I think, may be caused by the structure. But I do not have enough knowledge to name real, and not just hypothetical problems with this.

And how is his argument "He works my way, doesn't he?" the truth is, I would like to explain to him why this is a bad idea, and not come as a new seductive guy.

So, what problems can be caused by such a project structure? Or am I overreacting, and is such a structure completely perfect?

+7
c ++ linker
source share
2 answers

not to mention that the (clean) build of the project takes ~ 30 minutes

The main disadvantage is that changing any part of the code will require recompiling the entire program from scratch. If compilation takes a minute, it probably won't be significant, but if it takes 30 minutes, it will be painful; it destroys the execution workflow change-> compile->.

not to mention that a clean project project takes ~ 30 minutes

Individual translation units are usually usually a little slower to compile from scratch, but you only need to recompile each unit separately when they are changed, which is a major advantage. Of course, it’s easy to erroneously destroy this advantage by including a massive, often changing title in all translation units. Individual translation units require a little attention to do this correctly.

Nowadays with multi-core processors, slower assembly from scratch is mitigated by multiple parallelism, which allows multiple translation units (perhaps the drawback can even be overcome if the size of individual translation units falls into a sweet place and there are enough cores, you need to conduct a thorough study to find out )

Another potential drawback is that the entire compilation process must be memory-friendly. This is only a problem when this memory becomes larger than free memory on developer workstations.

In conclusion: The problem is that the approach with one massive source file does not scale very well for large projects.


Now a word about the benefits of justice

until optimizations are likely to end in redundant or unclear results

In fact, a single translation unit is easier to optimize than individual ones. This is due to the fact that some optimizations, in particular, the built-in extension, are not possible for translation units, since they depend on definitions that are not in the translation unit currently being compiled.

This optimization advantage was mitigated because link time optimization was available in stable versions of popular compilers. As long as you are able and want to use a modern compiler, as well as to optimize connection time (which may not turn on by default)


PS. It is very unusual to name a single source with the extension .hpp .

+4
source share

The first thing I would like to mention is the advantages of a project with a single compilation module:

  • A sharp reduction in compilation time. In fact, this is one of the main reasons for switching to SCU. When you have a regular project with n translation units, compilation time will increase linearly with the addition of each new translation unit. While with SCU it will grow logarithmically and adding new units to large projects is unlikely to affect compilation time.
  • Reduce compilation memory. Both disk and RAM. a "large" translation unit will obviously take up significantly more memory than each individual "small" translation unit containing only part of the project, however their aggregate size will significantly exceed the size of a "large" translation unit.
  • Some advantages of optimization. Obviously, you automatically get "all in a row".
  • Don't be afraid of "compiling from scratch" anymore. This is very important because this is what the CI server does.

Now to the cons:

  • Developers must maintain strict organizational discipline. Header protection, sequential ordering of #include directives, mandatory inclusion of headers directly required by the current file, proper forwarding, consistent naming conventions, etc. The problem is that there are no tools to help developers with this and even minor violations in the organization of the header lead to messy crash logs.
  • Potential increase in the total number of files in the project. See this answer for more details.

PS

  • The SCU organization in your case is similar to "soft boiled". By this, I mean that the project still has translation units that are not proper headers. Typically, this scenario occurs when an old project is converted to SCU.
  • If it takes ~ 30 minutes to create a project using SCU, I get the feeling that this is either not a project organization error (it could be an antivirus, not an SSD, recursive templates are inflated), or it will take several hours without SCU.
  • some numbers: compilation time decreased from ~ 14 minutes to ~ 20 seconds, reducing the size of the executable file 3 times (the result of converting an existing project to SCU from my experience)
  • real use case: CppCon 2014: Nicholas Fleury "C ++ in huge AAA games"
  • I could exaggerate a little, but it seems to me that the whole concept of "multiple translation units" (and static libraries) should remain in the past.
+1
source share

All Articles