|
|
Log in / Subscribe / Register

Splitting implementation and interface in C++

Splitting implementation and interface in C++

Posted Feb 24, 2025 17:22 UTC (Mon) by farnz (subscriber, #17727)
In reply to: Splitting implementation and interface in C++ by viro
Parent article: Rewriting essential Linux packages in Rust

Yes. The extra work of splitting something into an interface module and an implementation module is significant, and does not reduce the complexity of reasoning about a change, nor the amount of code that has to be reviewed for assessing validity of a change.

This is distinct from splitting the implementation up inside a single C++ module; having multiple module units, one for the exported interface and many for the internal implementation, makes a lot of sense, but having two separate C++ modules, one of which exports an unimplemented interface, and the other of which exports an implementation of that interface, is a mess, since it means I have to make sure that the two separate modules are kept in sync manually.

Why create that extra workload when I can have a single module with an internal module partition such that it's very obvious when I change the interface without changing the implementation to match, and where I have one thing to release instead of two?


to post comments

Splitting implementation and interface in C++

Posted Feb 25, 2025 0:00 UTC (Tue) by mathstuf (subscriber, #69389) [Link] (2 responses)

> Why create that extra workload when I can have a single module with an internal module partition such that it's very obvious when I change the interface without changing the implementation to match, and where I have one thing to release instead of two?

If the partition is imported into the interface for any reason, it must be shipped as well.

Splitting implementation and interface in C++

Posted Feb 25, 2025 10:01 UTC (Tue) by farnz (subscriber, #17727) [Link] (1 responses)

Sure, but I'm shipping full source anyway, and I can check for people exporting parts of the internal partition in CI, just as I'd have to have similar checks in place to stop people moving code from the interface module to the implementation module.

Remember that the goal here is one module, nicely structured for ease of maintenance, and thus split across multiple module units, with an internal module partition to make the stuff that's for internal use only invisible from outside the module, rather than multiple modules.

Splitting implementation and interface in C++

Posted Feb 25, 2025 11:57 UTC (Tue) by mathstuf (subscriber, #69389) [Link]

FWIW, CMake does this by enforcing that `PRIVATE TYPE CXX_MODULES` files are never imported from `PUBLIC TYPE CXX_MODULES` sources, so at least it can help enforce the "don't expose private bits in public interface units" part.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds