3 ms·
I don't see a problem with defining modules in Elixir scripts. It was a huge annoyance in Erlang though. Even scripts require some structure and code quality.
by nivertech 3y ago
I don't see a problem with defining modules in Elixir scripts. It was a huge annoyance in Erlang though.
Even scripts require some structure and code quality. I organize my bash scripts, otherwise they quickly become unmanagable.
If you dislike typing long module names, and for some unknown reasons won't use short alias (alias My.Long.Module.Name, as: M) or import. Then the best workaround is to use "M" as a module name:
#/usr/bin/env elixir
...
defmodule M do
...
def f, do: ...
...
end
...
M.f()
Anyway, I think there was Joe Armstrong's blog post, where he said that modules are just containers for functions. The way we decide which module to put a function is completely arbitrary. Sometimes it's very hard to decide, or maybe the same function could equally belong to several modules. I designing my toy programming language where functions do not nelong to modules or namespaces, but you can query them based on metadata like tags/types/docs/etc.