ketupia
How to Organize and Clarify Components and Services?
How are components organized so that developers know the intent of each component and system?
(Yes I’m using @moduledoc)
For example, I have the following components and services that all deal with the health of a character.
Components.TakeDamage,
Components.InstantHeal,
Components.IsDamaged,
Components.HealthPointRecovery,
Components.HealthPointRecoveryMilliseconds,
Components.MaxHealthPoints,
Components.HealthPoints
Systems.InstantHeal,
Systems.TakeDamage,
Systems.IsDamagedRemover,
Systems.HealthPointRecoveryScheduler,
Systems.HealthPointRecovery
I’m compelled to put them all in a namespace for organization and clarity purposes but if feels like that could an ECS anti-pattern. How should I organize components and systems?
Most Liked
APB9785
This should be OK, as long as the module name is the same in both the Component module file, and the Manager components/0 callback. The generators will create MyApp.Components.MyCompName by default, but you are welcome to change it afterwards. Perhaps in the future we could add a flag to the generator to include a sub-namespace from the start.
Note: I mentioned Components above but the same should apply for Systems.
ketupia
Any reason not to organize components and systems into namespaces (e.g. subfolders)?
ketupia
I moved a number of my components and systems into folders and equivalent namespaces. Yes. The code functions just fine.
The dashboard only shows the last bit of the module name so I’ll probably switch to a naming convention instead. (not asking for a change - just sharing my experience)
You can see in the screen shot that there’d be no way to know that the components belong together as highlighted. Further Status is used more than once so I don’t know which is which.








