Hacker Newsnew | past | comments | ask | show | jobs | submit | reactjs_'s commentslogin

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++.


Rust's re-exports also allow you to design your public module structure separate from your internal structure.


Like most languages with modules.

Rust, Modula-2 and Ada are probably the only ones with module nesting.


Notably many languages in ML family have first class modules.


Only Standard ML and OCaml, as far as I am aware.

However this is a different kind of modules, with them being present on the type system, and manipulated via functors.


I 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.


The 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.


Not 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 ;)


That 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.


Just 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.


Fascinatingly, 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.


FWIW, Fortran does have submodules.


I 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)


I 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.


It was well designed. Hence the "it got stuff done".

But it was also behind the times. And, if we're fair, half of its reputation comes from the fact that half of the F77 code was written by PhDs, who usually have... let's call it a unique style of writing software.


Indeed. Two PhD students came to see me when the polytechnic I worked for switched from a Dec10 to two IBM 4381s.

[them] How can we get our code to work on the IBM?

[me] (examines code) This only looks vaguely like Fortran.

[them] Yes, we used all these wonderful extensions that Digital provides!

[me] (collapse on the floor laughing) (recover) Hmm. Go see Mike (our VAX systems programmer). You may be able to run on our VAXen, but I can't imagine it running on the IBMs without a major rewrite. Had they stuck to F77 there would have been few problems, and I could have helped with them.

Portability is always worth aiming for, even if you don't get all the way there.


I'm so old, those jokes were about me.


Fogeys unite! ;) (They're about me, too)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: