pillaiindu
Why do we need name of the App everywhere in Phoenix?
I’m not an Elixir or Phoenix professional in any way. I’m just a noob, a starter, but I want everything a bit simpler.
I was reading Programming Phoenix, and these thoughts came to my mind.
- Why do we have
defmodule RumblWeb.UserView doand not justdefmodule UserView do? Why do we have thisAppNameprepended everywhere?
Isn’t it better not to have the AppName prepended? - Why do we have
Rumbl.Repo? Why don’t we have simplyEcto.Repo?
I think Rails have this kind of conventions because there it’s OO and in OOP you have that object (for example called Rumbl) and you have everything attached to that object, but here we don’t have objects, so why prepend this thing to everything and have extra burden on brain.
I’ll say once again that I’m a noob and I might be wrong, but again I think it will be easier for Noobs to adopt something if it’s simpler, and we should leave Conventions (and copying Rails) aside if it can make it simpler.
Most Liked
michalmuskala
The answer is quite trivial: to avoid module name conflicts with the standard library, other libraries and some other code you might import into your project.
Aliasing makes this much less annoying than it initially seems.
michalmuskala
IIRC there’s only one place where you actually use the Ecto.Repo module and that is inside the AppName.Repo module’s use call. Everywhere else you call your custom module directly.
The reason for that particular design is that it makes it trivial to connect to multiple databases at the same time - for each database you have a separate repo module - this is very complex in Rails because of the global nature of database connection.
kokolegorille
There is no obligation to name this like that, You are free to use simply UserView if that is what You prefer. It is just a convention.
It does not even reflect folder structure. It’s just a convention, making it easier for us to think about some kind of namespace hierarchy.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









