r/cpp • • Apr 09 '26

Writing only decoupled code

https://middleraster.github.io/DAG/HeaderOnlyNoForwardDeclarations.html
12 Upvotes

17 comments sorted by

View all comments

Show parent comment

2

u/ir_dan Apr 20 '26

"Decoupled" here means that software entities know little about each other. It means that when one header changes, you don't have to go and change all of the other headers yourself by writing new/adjusted code.

Your view is that "coupling" is when the compiler-has to redo work. Theirs is that "coupling" is when **you** have to redo work.

1

u/Big_Target_1405 Apr 20 '26

It's more that the scope of what you can change is limited when the data layout is exposed in headers.

An ABI boundary really enforces decoupling

In my view forward declarations (of class and structs) give you type safety without exposing data structures, which is ideal.