| Modules are an attempt to make part of the language what currently requires a convention: - A component is a collection of related code. - The component has an interface and an implementation. - The interface is a header file (e.g. *.h) that is included (but at most once!) using a preprocessor directive in each dependent component. - The header file contains only declarations, templates, and explicitly inline definitions. - The implementation is one or more source files (e.g. *.cpp) that provide the definitions for what is declared in the header, and other unexposed implementation details. - Component implementations are compiled separately (usually). - The linker finds compiled definitions for everything a component depends upon, transitively, to produce the resulting program/dll. So much can go wrong! If only there were a notion of components in the language itself. This way we could just write what we mean ("this is a component, here is what it exports, here are the definitions, here is what it imports"). Then compiler toolchains could implement it however they like, and hopefully optimize it. |