3 ms·
Here’s the thing I don’t get about module partitions: They only seem to allow one level of encapsulation. Program - Module - Module Partition wh
by reactjs_ 8mo ago
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++.
- pdpi 8mo agoRust's re-exports also allow you to design your public module structure separate from your internal structure.
- groby_b 8mo agoI don't think you're missing something. The standards committee made a bad call with "no submodules", ran into insurmountable problems, and doubled down on the bad call via partitions. "Just one more level bro, I swear. One more". I fully expect to sooner or later see a retcon on why really, two is the right number. Yeah, I'm salty about this. "Submodules encourage dependency messes" is just trying to fix substandard engineering across many teams via enforcement of somewhat arbitrary rules. That has never worked in the history of programming. "The determined Real Programmer can write FORTRAN programs in any language" is still true.
- bluGill 8mo agoThe C++ committee tries to do features with room for future extension. They believe that whatever you want from sub-modules is still possible in the future - but better to have a small (as if modules is small) thing now than try for perfects. We can argue about submodules once we have the easy cases working and hopefully better understand the actual limitations.
- groby_b 8mo agoNot to put too fine a point on it: The world has 35 years of experience with submodules. It's not rocket science. The committee just did what committees do. And sure, "future extension" is nice. But not if the future arrives at an absolutely glacial pace and is technically more like the past. This may be inevitable given the wide spread of the language, but it's also what's dooming the language to be the next COBOL. (On the upside, that means C++ folks can write themselves a yacht in retirement ;)
- bluGill 8mo agoThat is 35 years of different things tried, some that work better than others, some that are not compatible with others. Trying to figure out what is the best compromise while also making something that doesn't break existing code is hard when there are a lot of people who care.
- pornel 8mo agoJust getting to this barely-working state took C++ longer than it took to create all of Rust, including a redesign of Rust's own module system.
- pklausler 8mo agoFWIW, Fortran does have submodules.
- groby_b 8mo agoI suppose we shall amend to "The determined Real Programmer will fix FORTRAN" ;) But, for the folks who didn't grow up with the Real Programmer jokes, this is rooted in a context of FORTRAN 77. Which was, uh, not famous for its readability or modularity. (But got stuff done, so there's that)
- pklausler 8mo agoI'm so old, those jokes were about me.
- groby_b 8mo agoFogeys unite! ;) (They're about me, too)
- zabzonk 8mo agoI wrote a lot of F77 code way back when, including an 8080 simulator similar to that written by Gates and Allen used to build their BASIC for Altair. I don't know what language they wrote theirs in, but mine was pretty readable, just a bit late. And it was very portable - Dec10, VAX, IBM VM/CMS with almost no changes. I think F77 was a pretty well designed language, given the legacy stuff it had to support.
- fl0ki 8mo agoFascinatingly, I am not aware of any real issues with how Rust did nested modules. It even treated crates as top-level modules for most language-level purposes. I am sure there are nuanced reasons that C++ can't do quite the same, but the developer experience consequences can't be worth it.
- pjmlp 8mo agoLike most languages with modules. Rust, Modula-2 and Ada are probably the only ones with module nesting.