• How do you decide what deserves its own file?
    3 replies, posted
I'm just curious how people on here decide which parts of the program go into which file, do you do 1 class per file? 1 function per file? Make a file for each "subsystem"? If so, what is a subsystem to you? I know this is somewhat language dependent, but still slightly interesting to hear what people do. I usually program in C and tend to make a file based on loose sub-areas of the whole program. (eg. there's a main file to do platform specific things, and then a file for things like "draw_functions.c" or "common_defines.c" or "entities.c") and try to use the minimum amount of files to still be neatly organized (to me at least, I don't work with other programmers and am just a hobbyist, so maybe it's ugly to others). Please post your preferences for source file organization.
One file per class in OO languages (with the exception of proxy classes), one file per subsystem in other things like Lua. In C I still tend to follow an object oriented structure, just with function prefixes and struct pointers instead of classes.
If it's a really small class, or the class/enum is only used in one other class, I put it in the same file. Otherwise usually 1 class per file. (C#)
I generally try to keep it to one published class per file, _maybe_ one file for multiple variants (e.g. differing by generic type parameters). In something like Angular, you're likely to end to with anywhere from three to about five files per (component) class if you want to keep things organized, depending on how much you care about testing and keeping the dependency graph manageable.
Sorry, you need to Log In to post a reply to this thread.