apache / celix

Apache Celix is a framework for C and C++14 to develop dynamic modular software applications using component and in-process service-oriented programming.
https://celix.apache.org/
Apache License 2.0
158 stars 84 forks source link

Minimize over-inclusion to reduce accidental complexity in header files #715

Open pnoltes opened 6 months ago

pnoltes commented 6 months ago

Intro

If (public) header files include too much upstream header files, this can increase accidental complexity (accidental complexity arises when a software system becomes unnecessarily complicated due to factors that are not inherent to the problem being solved, but are rather a byproduct of the chosen tools, technologies, or approaches).

Several reasons over-inclusion add accidental complexity:

Minimize symbols

An alternative to including a header file which contain many unneeded symbols is to use forward declaration or only include header files with a minimal number of symbols, forward declaration and/or opaque typedefs.

This will prevent adding to much unneeded symbols during a compilation of a source file and prevent downstream users to accidental/unintellionally get symbols they did not specifically include.

Note that creating header files with minimal symbols/forward-declaration/opaque-typedefs, can only be done for Apache Celix own header files.

Tasks

Update the coding guidelines

Update the coding guidelines so that functional coherent C header files are split up in multiple header files using something like the following scheme:

And functional coherent C++ header files are split up in multiple header files using something like the following scheme:

Update framework and libs

Update at least the framework and libs to following the aforementioned updated header coding style. The bundles and bundle api/spi libs can be updated using a the last Boy Scout rule.

Optional add build tooling to check include behaviour.

Maybe it is possible to use something like include what you use tool to check include behaviour.

pnoltes commented 6 months ago

note feedback is welcome