manhvu
Proposal: Add support namespace for module
In a large repo, working with module need to add alias too much is quite annoyed and not good for organizing code.
I think better add support for namespace can bring more convenient for dev.
This is a basic example for namespace cross multi modules.
Example:
defmodule MyApp.A do
namespace MyApp.DataProcessing
def a do
# do somethings
end
defmacro macroA(name, opts) do
#...
end
end
defmodule MyApp.B do
namespace MyApp.DataProcessing
def b do
# somethings
end
end
defmodule MyApp.C do
namespace MyApp.DataProcessing
def do_something(data) do
data
|> A.a()
|> B.b()
end
A.macroA :wrapper, type: :json
end
LS can easily to suggest dev in a namespace.
Pros:
- Less typo like add alias for module.
- Make code clean than before.
- Better for LS suggest in case work in namespace.
Cons:
- Make complicated if bring support for
import,requireoruse. - Can make dev confused.
Most Liked
benwilson512
This idea is essentially implemented in the library Boundary GitHub - sasa1977/boundary: Manage and restrain cross-module dependencies in Elixir projects · GitHub
Do you have any thoughts on how this proposal differs, beyond basically the implicit aliasing?
FlyingNoodle
BartOtten
At mobile so in short:
defmodule DataProcessingAliases do
defmacro __using__(opts) do
quote do
alias MyApp.A
alias MyApp.B
alias MyApp.C
end
end
end
Now you can use DataProcessingAliases in the modules. Mixed ground between explicit and implicit…?
Last Post!
BartOtten
Ah, forgot about that. Need to expand it before passing it as function argument. Small change but then you can just use module names.
Popular in Proposals: Ideas
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









