kellysmith12.21
2020-11-28 08:25:45

When organizing code, is there a rule of thumb for when to use a subcollection and when to use a submodule?


laurent.orseau
2020-11-28 09:29:58

My personal rule of thumb is: if you expect the code to be small, a submodule can be good enough (say, just to re-export things, or just wrap some things, or a small main). If it grows too much, then separate it into a different file.


samdphillips
2020-11-28 18:02:32

I don’t have a mnemonic but here is how I remember them (module X L ...) is a standalone module, cannot require enclosing module (module+ X ...) combines (or adds) all of the same named submodules into a (module* X #f ...) (module* X L ...) is a module but it can require the enclosing module

Multiple additions (module+) is a multiplication (module*) is the best sort of mnemonic I have…


notjack
2020-11-29 02:49:53

Generally I lean towards subcollections by default. Submodules I use for things that obviously can’t be subcollections, such as test (tests in the same file are incredibly useful) and main submodules, or a private submodule that re-exports something I need to use in another part of my package but which I don’t want to be part of my package’s public API.