←back to thread

141 points vblanco | 3 comments | | HN request time: 0.207s | source
1. 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 #
2. 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.

3. pjmlp ◴[] No.44441445[source]
It makes lots of sense to anyone used to large scale software development.

It is no accident that Ada, Java, .NET, and oldies like Delphi, Eiffel, Modula-2 and Modula-3 have similar approaches.

Even the way D and Python modules and packages work, or the whole crates and modules approach in Rust.

Naturally folks not used to Web scale don't get these kind of features.