Unnecessary #include statements can increase build times, make code harder to understand, and make restructuring more difficult. It is trivial to find these with Structure101 Studio, so you can remove them from the code, or from the model prior to further analysis and restructuring.
Finding redundant #includes means finding file-to-file dependencies that contain an #include, but whose weight is 1 – indicating that #include is the only dependency between the files.
You’re going to show the file slice on the Structure tab, so it helps to switch off dependencies for now. To do this, click on this button (not the dropdown next to it) so that it is deselected:
Now select the file slice using the slice button. This causes all the files to be displayed in the LSM viewing area:
Now go to the panel below the LSM and select the Map Contents tab, and the Dependencies sub-tab. This shows all the dependencies on the LSM (not currently shown, but they are there). Click once on the “weight”, then on the “Primary usage” column header – this sorts the table of dependencies first on the primary usage, then on the weight. This means that all #includes of weight 1 are in a contiguous block in the table. Scroll down to find these:
Now you can multi-select all of the redundant #includes by clicking the first, and scrolling down to, and shift-clicking on the last.
If you wish to export the sublist, right-click/copy-all will move them to the clipboard:
… from whence you can paste to a spreadsheet, or Jira, or wherever you wish…
And/or if you wish to continue analysing and restructuring activities in advance of the source code catching up, you can remove them from your Structure101 project by clicking on the “cut” button while the dependencies are still selected:
When you remove the dependencies in the Structure101 project, all the remove actions are added to the current Action list:
These are re-applied whenever you open or update the project with this action list selected. This means that you can now switch to a lower granularity model (for example if it’s a huge project, this can improve UI responsiveness). Go to the project settings and change the granularity:
After changing the granularity, the project will be loaded with the lighter model (no file internals), but the superfluous #includes will be re-removed by the action list. Note that you cannot remove redundant #includes in overview (or includes-only) granularity because you need to see the function-level dependencies in order to tell which file-level are redundant.
By the way, while you are tidying up the #includes, you may want to look at all the remaining dependencies for which there is no corresponding direct #include. Still in the file slice, and with the “Map contents”/”Dependencies” displayed, any dependencies whose “primary usage” is not “includes” are inter-file usage for which there is no #include statement…
Some of the features shown above are relatively recent to Structure101 Studio, so if you’re not seeing something used, you’ll need to grab the latest release.