budgie
How should I name related modules with the least repetition possible?
Not sure if there’s an official answer for this in Elixir land, but it’s not the first time I’ve encountered this. I want to name a bunch of related components that are each a part of some bigger component. Let’s call the big one Session. What do you think of these three examples, and can you think of another way to do it?
# Inside of /lib/app_web/components/session/
AppWeb.Session.SessionStartedComponent
AppWeb.Session.SessionPendingComponent
or
# Inside of /lib/app_web/components/session/
AppWeb.Session.StartedComponent
AppWeb.Session.PendingComponent
or without the intermediate module name part, but still in own directory
# Inside of /lib/app_web/components/session/
AppWeb.SessionStartedComponent
AppWeb.SessionPendingComponent
What is the preference and what is most standard in the Elixir world? I know that directory names usually reflect the segments of a module name, but is it obligatory?
Most Liked
APB9785
I like option 2, unless you also have
AppWeb.PostDrafts.StartedComponent
AppWeb.Countdown.StartedComponent
...etc
then probably option 1 would be better imo
(not a big fan of diverging folder structure from module namespacing)
sodapopcan
I used to feel this way and quite strongly so. But due to BEAM not caring about file names and not having to import based on paths, I’ve actually found it super liberating to keep the file system for organization and using different naming schemes for some modules. It means I don’t need to alias so much which I try and avoid. It’s not to say that I don’t alias, but my default is to not do it until it becomes a readability problem.







