Are below codes equivalent? As to invoke a module method, in both cases, one will use Utilities.StringUtils.some_method(...)
Nested modules
defmodule Utilities do
defmodule StringUtils do
end
end
Modules with dot in the name
defmodule Utilities.StringUtils do
end
Yes and no. The first definition automatically defines an alias based on the module name:
defmodule Utilities do
defmodule StringUtils do
end
# Can access the module as StringUtils
end
While the second:
defmodule Utilities.StringUtils do
# Cannot access the module as StringUtils
end
Other than that, the code and module defined by both are exactly the same.
Yes, both are translated exactly to the symbol (in Erlang a module is referenced by its symbol):
:"Elixir.Utilities.StringUtils"
There aren't really nested modules in Erlang, it's just something Elixir simulated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With