←back to thread

141 points vblanco | 1 comments | | HN request time: 0.21s | source
Show context
KingLancelot ◴[] No.44437077[source]
To be fair, C++’s modules make no sense, just like their namespaces that span multiple translation units.

It’s just more heavy clunky abstractions for the sake of abstractions.

replies(2): >>44441294 #>>44441445 #
1. MathMonkeyMan ◴[] No.44441294[source]
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.