logoalt Hacker News

C++ Modules Are Here to Stay

71 pointsby faresahmedlast Saturday at 6:49 AM85 commentsview on HN

Comments

yunnpptoday at 8:21 PM

I recently started a pet project using modules in MSVC, the compiler that at present has best support for modules, and ran into a compiler bug where it didn't know how to compile and asked me to "change the code around this line".

So no, modules aren't even here, let alone to stay.

Never mind using modules in an actual project when I could repro a bug so easily. The people preaching modules must not be using them seriously, or otherwise I simply do not understand what weed they are smoking. I would very much appreciate to stand corrected, however.

show 5 replies
fasteriktoday at 10:51 PM

I get by without modules or header files in my C++ projects by using the following guidelines:

- Single translation unit (main.cpp)

- Include all other cpp files in main

- Include files in dependency order (no forward declarations)

- No circular dependencies between files

- Each file has its own namespace (e.g. namespace draw in draw.cpp)

This works well for small to medium sized projects (on the order of 10k lines). I suspect it will scale to 100k-1M line projects as long as there is minimal use of features that kill compile times (e.g. templates).

show 2 replies
reactjs_today at 7:24 PM

Here’s the thing I don’t get about module partitions: They only seem to allow one level of encapsulation.

    Program
    - Module
      - Module Partition
whereas in module systems that support module visibility, like Rust’s, you can decompose your program at multiple abstraction levels:

    Program
    - Private Module
      - Private Module
        - Private Module
        - Public Module
      - Public Module
Maybe I am missing something. It seems like you will have to rely on discipline and documentation to enforce clean code layering in C++.
show 3 replies
rienbdjtoday at 7:56 PM

From the outside looking in, this all feels like too little too late. Big tech has decided on Rust for future infrastructure projects. C++ will get QoL improvements… one day and the committees seem unable to keep everyone happy or disappoint one stake holder. C++ will be around forever, but will it be primarily legacy?

show 1 reply
w4rh4wk5today at 7:26 PM

https://arewemodulesyet.org/ gives you an overview which libraries already provide a module version.

show 1 reply
jokoontoday at 10:57 PM

I am curious to know if that 8.6x speedup is consistent.

I don't see many "fair" benchmarks about this, but I guess it is probably difficult to properly benchmarks module compilation as it can depend on cases.

If modules can reach that sort of speedup consistently, it's obviously great news.

fookertoday at 8:15 PM

C++ templates and metaprogramming is fundamentally incompatible with the idea of your code being treated in modules.

The current solution chosen by compilers is to basically have a copy of your code for every dependency that wants to specialize something.

For template heavy code, this is a combinatorial explosion.

show 3 replies
cmovqtoday at 7:05 PM

Can someone using modules chime in on whether they’ve seen build times improve?

show 2 replies
Night_Thastustoday at 7:56 PM

The fact that precompiled headers are nearly as good for a much smaller investment tells you most of what you need to know, imo.

feelameetoday at 7:09 PM

why use modules if PCH on your diagram is not much worse in compile times?

show 3 replies
TimorousBestietoday at 7:35 PM

I can’t deploy C++ modules to any of the hardware I use in the shop. Probably won’t change in the near-to-mid future.

It seems likely I’ll have to move away from C++, or perhaps more accurately it’s moving away from me.

show 2 replies
up2isomorphismtoday at 8:36 PM

“C includes show it age.” But C++ is stating not because of there is a “++” there but because of there is a “C”.

whobretoday at 6:52 PM

> auto main() -> int {

Dude…

show 7 replies
GrowingSidewaystoday at 7:57 PM

[dead]