As a new developer to swift, I'm looking to get more information on best practices for organizing large projects. I’ve read quite a bit about modules and element nesting, and I understand that “namespaces/submodules” is a bit of a controversial topic / still being worked out, but I’ve never reached a satisfying answer as to how to approach this.
Right now, in 2018, what is the best practice for organizing code? Suppose my domain looks like the following:
I have a top level domain called “Foo”. In this domain, I plan to have large libraries of components that other people can use called “Core”, “Widgets”, “Maguffins”, “Transforms” and “Utilities”. Inside of each of these libraries there will be multiple classes provided that could be described in terms of subdomains (or subsubdomains). For example, “Core” might have a “Maths” subdomain and a “Scaffolding” subdomain, and the “Maths” subdomain might have subdomain of its own like “Trig” and “Calculus”.
I realize this example is a bit contrived but I find myself wondering how to structure code within an area that has deep domains / will end up with large segments of code.
Reading what I can find about SPM, it seems like I’m required to at least have a top level folder in the “Sources” directory, and then inside that I’m allowed to have a number of module subdirectories (?):
Sources
| - Foo
| - Core
| - Widgets
| - Maguffins
Packages.swift
While this will work for shallow projects, I’m unsure how this will scale up. Am I allowed to have subfolders underneath the “module” subfolders (e.g. “Maths” under “Core”)? Do I need to plan to break this across library boundaries; i.e. should I have a “FooCore” and a “FooWidgets” library? How does namespacing work there?
I’ve also seen the things about enum based “namespacing” but the asymmetry of needing to write “enum Foo” in one file and “extension Foo” in others seems hard to follow. I suppose in my case that the “enum” version could go in the “Core” library and everything else could follow suit. Is this considered good / bad practice?
Any guidance folks can provide would be greatly appreciated!