sezaru

sezaru

Why some Phoenix modules (ex. Controllers) doesn't reflect its file path

Hello,

I was wondering, why Phoenix doesn’t follow the “unwritten rule” that your module path should be identical to the file path in the system (ex: MyApp.Bla.Ble would be in lib/my_app/bla/ble.ex) for some of its framework files?

That may sound dumb, but one of the things that I like most about Elixir is the well-defined patterns that everyone uses, variables, atoms and files should use underscore, modules should be camel case, etc. This, IMO, makes the code well organized, easy to read, and easy to find. And in my experience, most of the Elixir libraries follow these patterns (except Google ones, ofc).

At the same time, you have some parts of the Phoenix Framework which seem to ignore this. For example, instead of having MyAppWeb.Controllers.Page which would be stored in lib/my_app_web/controllers/page.ex, we have MyAppWeb.PageController which is stored in lib/my_app_web/controllers/page_controller.ex. The same thing happens with views, components, etc.

I know I’m exaggerating, but this for some reason makes me remember java class names like AbstractSingletonProxyFactoryBean :sweat_smile:

I’m not saying that this is wrong or anything, it mostly depends on the user’s opinion in the end… But at the same time, having the module reflect the file path makes things easy to find and makes, IMO, the language not dependent on IDEs, so this made me wonder why Phoenix does this, I’m pretty sure there is a good reason.

Marked As Solved

LostKobrakai

LostKobrakai

Essentially all parts of my_app_web ignore this.

The reason being is to prevent you having three (or more) page.ex files/….Page modules in your codebase (schema/controller/view/…) which makes it hard to search by filename or module. Given this overlap of names is common place and not a rare occurance it makes sense to break with a convention, given it’s only a convention and not enforced by anything.

Where Next?

Popular in Discussions Top

blackode
Elixir Upgrading is so Simple in Ubuntu and It worked for me Ubuntu 16.04 git clone https://github.com/elixir-lang/elixir.git cd elixir...
New
sashaafm
Piggy backing a bit on @dvcrn topic BEAM optimization for functions with static return type?, I’ve been trying to understand in a deeper ...
New
fireproofsocks
This is more of a general question, but I’m wondering how other people in the community think about the pattern matching in function sign...
New
AstonJ
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
ejpcmac
I have discovered Nix last month and I am currently on my way to migrating to it—both on macOS at home and the full NixOS distrubution at...
New
Ankhers
Just a little information upfront. Generally speaking, if I feel like I need to either break a pipe chain or use an anonymous function in...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
tomekowal
Hey guys! I want to create a toy project that shows a chart of temperature over time and updates every 5 seconds. I feel LiveView is per...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
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
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
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement