I’m creating a package (mostly for personal use, and for sharing with a few people, but not like “going into the general repository” standards here), and one of the questions I’m running into is where exactly to split the files up. At some level, this feels like a personal choice, but I’ve been getting into learning the idiomatic/Julian ways to program things. So, are there basic guidelines as to where to split the files in the src directory up?
For a more specific example, that I’m really quite on the fence about: I’ve got a struct that is composed of other structs for a few layers. It’s basically such that struct A is composed of an array of struct B’s and some other stuff, and struct B is composed of an array of struct C’s and some other stuff. Right now, I have all of the struct definitions and their “constructors” in the same file. But it’s getting a little large. Are there general guidelines to when I should split that file, or should it have always been split from the beginning? And if I do split it, should I put them all in a subdirectory of src? Additionally, I have some utility functions that are basic handling of some of these structs in a different file. Should these be included with the struct’s definitions/constructors?
Even if there aren’t general guidelines or such, I would love to hear what’s worked for you! Let me know if I need to be more specific with my example
There aren’t really guidelines other than to aim for “cleanliness” if you can. At a bare minimum, it should at least make some sense to someone not familiar with your package.
I’d say if it is really really simple, just have a single file. It sounds like you are beyond that though. I would probably begin splitting files into whatever seems most natural, but keeping them at the top level (under
src). It is common to split by types I think. Only the biggest and/or most complex packages really need subdirectories.
I think it is common to factor out utility functions into a toplevel file that is appropriately named.
One somewhat technical argument one can make on this topic is that it makes sense to put independent (e.g.
Array code and
String code) or one-sidedly independent parts (e.g. basic
Array functionality and linear algebra code) into separate files. This simplifies the development process for two (related) reasons:
- Cleaner git history since you only have to look at the changed files to see which parts could possibly have been broken by a change.
- Easier development and testing: if you think your linear algebra code stinks but the basic array code is fine, you can simply delete the linear algebra file but keep the array file. Similarly, if you mirror your file structure for the tests and you are working on the linear algebra code, you can temporarily not
include() the array tests to speed up the testing.