budgie

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

APB9785

Creator of ECSx

I like option 2, unless you also have

AppWeb.PostDrafts.StartedComponent
AppWeb.Countdown.StartedComponent
...etc

:sweat_smile: then probably option 1 would be better imo

(not a big fan of diverging folder structure from module namespacing)

sodapopcan

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.

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement