|
Header Files Are Not Simple
|
Header Files Are Not Simple
Header files are not simple because they duplicate information. Header files are useful for compilers and linkers, because they compactly supply the information that those tools need about external symbols, including types and function signatures. But they are a nuisance for coders and reviewers.
Design changes often have to be made in two places: in the header and in the definition. This is a version of the copy-paste-edit anti-pattern.
In olden times it was unthinkable to force compilers to translate whole systems at one time. Instead, for resource efficiency, each separate file was translated separately, and this required help from the coder in the form of header files. The idea was to efficiently fill internal data structures in standalone tools, not to make use of a system-wide database.
This was bad enough in C, but it was only made worse in C++ where semantics were added to header files: put a method definition in a header file and it becomes inline!
We will only mention in passing the horror of touching a header file (perhaps by modifying an email address in a comment) and forcing the unnecessary rebuilding of an entire system.
There are Ada-like languages (e.g. VHDL) that see a data-hiding advantage in header(-like) files. But this is a derived advantage that does not require source-level duplication of information.
The simple solution is for tools to use tools to get the external symbol information that they need, and not to make humans provide it for them.
|
Header Files Are Not Simple |
|