Hey π , I have about a year of experience developing in Elixir, and comming from Python I really wish there was a way to have relative aliases from the current module.
For example, consider this project structure:
# I know elixir modules are independent from the file structure but it's easier to visualize it this way (I think)
.
βββ app/
βββ some_module/
βββ some_other_module/
βββ pipeline/
βββ pipeline.ex # App.SomeModule.SomeOtherModule.Pipeline
βββ extract.ex # App.SomeModule.SomeOtherModule.Pipeline.Extract
βββ transform.ex # App.SomeModule.SomeOtherModule.Pipeline.Transform
βββ load.ex # App.SomeModule.SomeOtherModule.Pipeline.Load
If I want to alias Extract inside Pipeline then I would have to do something like:
defmodule App.SomeModule.SomeOtherModule.Pipeline do
alias App.SomeModule.SomeOtherModule.Pipeline.Extract
...
end
Which is fine, but seems redundant. This specially bugs the more levels deep we get into the project.
A Python-esque way of aliasing would be:
defmodule App.SomeModule.SomeOtherModule.Pipeline do
alias .Extract
def foo do
Extract.run()
end
...
end
Which would append the atom to the current module. This obviously doesn't work, but you get what I'm getting at.
Something I've been toying with it's this implementation:
defmodule App.SomeModule.SomeOtherModule.Pipeline do
def foo do
__MODULE__.Extract.run()
end
...
end
Which gets the job done, but kind of obscures the fact that I'm using another module.
So I'm wondering if you've had this situation in your projects and if so, how have you tackled it?
Thanks! π