cevado
when using phoenix generators it creates MyAppWeb.ResourceController and put it inside /lib/my_app_web/controllers/resource_controller.ex file. I was thinking if it wouldn’t be better if it followed the elixir standards and have a MyAppWeb.Controllers.Resource in a /lib/my_app_web/controllers/resource.ex file.
I understand that this is done that way so phoenix can abstract the default view from the controller module name, but it could be an option passed to MyAppWeb when using it. Something like use MyAppWeb, controller: [default_view: ViewModule].
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
I’m posting this in response to Jose’s recent tweet (Cr. link) :
People are sleeping on Elixir for a coding harness:
Hot-code swappi...
New
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes.
We’re a small ...
New
This might be a bit disturbing for some but it’s happening - computers running on living human neurons. They’ve made them smart enough t...
New
Other Trending Topics
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
Well, people use
aliasa lot and having e.g.Usersis going to be confusing, especially having in mind that Phoenix encourages you to have context modules with the model name in plural. So what wouldUsersmean? The context or the controller?al2o3cr
Beyond the aliasing issue @dimitarvp mentions, the bigger concern IMO is the “tab problem”.
In short, having many files with similar / identical names can cause confusion when users have an editor that only displays the base name of the file as a label. In your example, is a tab labeled
resource.exthe controller or the corresponding schema?Rust had a similar (but bigger) situation a few years back; the “default” place to put code for a module
The thread of discussion is long and tangled, but you can start from the final RFC that changed the approach so that
foowas infoo/mod.rs- so if you had many crates open, ALL the tabs would be namedmod.rsfoo.rswould work.tfwright
Wouldn’t the easy solve there to use the
:asoption? Although as I type that I realize my approach in Elixir apps that have this problem is to just alias up to the namespace so I can reference X.Users and Y.Users in any module that needs to reference both.dimitarvp
Indeed but then why rename in the first place? You’d save writing something like 5-6 characters at best, at the cost of using unnecessary renaming in other form (namely the
:asoption).tfwright
Good point. It seems like the as option only really helps with the NS immediately above the mod isn’t enough to distinguish it but something higher up is. But I’ve never worked on a a system where that was true.
dimitarvp
My rule of thumb for Elixir projects is: if your namespaces have 4 levels then it’s probably time to break apart your app.
As all such rules there are exceptions, obviously, but us the humans can only keep so much complexity in our heads.
BTW I never liked the “controller” moniker anyway. It’s IMO a misnomer and it would be more accurate as “HTTP inbound sink” (or something more brief than that; my English vocabulary isn’t great). The hell does it “control”?
If it were up to me I’d like have files like these:
lib/myapp_web/inbound/users_server.exlib/myapp/orders/cart.exlib/myapp_web/renderers/line_item_viewer.exOr some such.
cevado
@dimitarvp but why someone would reference a controller outside of a router or the actual controller test?
@al2o3cr isn’t that already a problem with the default elixir naming standard? why having two standards would solve that?
I think the main objective should be consistency. unfortunately, the web folder is an alien thing to the rest of the elixir code of a project.
dimitarvp
They very likely wouldn’t but aliasing things is a fact of life and IMO somebody is bound to get confused eventually. I wouldn’t risk it.
hauleth
This is exactly the approach I am using in my projects. Example controller. I really do not like the default approach where the “regular” naming scheme is broken. Thanks to that approach it router is IMHO much cleaner:
See Mama, no
Controllerrepeated over and over again.However recently I am thinking about grouping the controller, view, and templates within single “domain-oriented” directory.
cevado
i’ve been doing that too. i’d love to see it as a standard in the framework, and I say that because generators usually direct people to a standard solution. i feel so weird on the projects that I’ve worked that are the necessity of custom plugs and people created and named plugs according to the “phoenix standard”.
personally I only use generators for migrations and everything else I create by hand so it doesn’t impact me that much. one other thing that I usually change is the folder names too: