elt547

elt547

Anyone have tips for code organization?

I’m new to elixir, and I’m finding that I often have files have many responsibilities, which I’m not fond of. One frequent occurrence of this I’m seeing is the context files in a phoenix project. If you have many different schemas under that context, you end up having a ton of boilerplate like create_user, create_account, create_admin right next to each other. I really don’t like this and I could see this growing out of control very quickly in a project of consequence. I can’t open up modules for modification in more than one file, as things are overwritten. I’m at a loss at how to deal with this and in my opinion it’s a big downside of using elixir/phoenix and the default code generators in phoenix.

Does anyone have any tips or resources on using files to separate code in elixir?

Most Liked

beepbeepbopbop

beepbeepbopbop

I would also recommend reading a multi part series as well that Sasa wrote: https://medium.com/very-big-things/towards-maintainable-elixir-the-core-and-the-interface-c267f0da43

That’s one part of the 4 I think, of which every single one has incredible value to be pulled from. Like anything, don’t be too dogmatic about it, it’s very likely you won’t nail it the first couple of times, but as long as you have these concepts in the back of your head, certain patterns tend to emerge.

Hermanverschooten

Hermanverschooten

I like. what Sasa does in his talks, eg https://www.youtube.com/watch?v=6sNmJtoKDCo

eahanson

eahanson

One trick is to generate a new Phoenix app in some scratch directory, use Phoenix schema etc. generators there, read the generated code, and then implement something similar by hand in your real app, putting everything where you want it.

Where Next?

Popular in Questions Top

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
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
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 Postgres...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
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

Other popular topics Top

mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement