I want to know why defmodule
exists in Elixir. What does it do actually?
For further actions, you may consider blocking this person and/or reporting abuse
I want to know why defmodule
exists in Elixir. What does it do actually?
For further actions, you may consider blocking this person and/or reporting abuse
Hanzla Baig -
Hanzla Baig -
Kevin Naidoo -
Chris Trag -
Top comments (5)
Muhammed,
Hard to answer the question since you don't elaborate clearly, have to read the documentation and after doing so is that explanation not clear?
If you haven't done so start here:
elixir-lang.org/getting-started/mo...
and
hexdocs.pm/elixir/Kernel.html#defm...
Simply, I just asked why
defmodule
exists in Elixir unlike other languages.Muhammed,
You missed the point I tried to make on my answer, I was trying to point you are not asking a good enough question, and you will clearly not get a good enough answer.
You tried to clarify saying why does this piece of syntax exist in elixir and not in other languages, which is still not a good question, but let's elaborate.
Briefly let's take Ruby as an example as Elixir takes heavy inspiration from Ruby in terms of syntax. In ruby we have a module macro, so you can do something like
Same code in Elixir would be fairly similar minor difference, now if what you are actually trying to get at is that you want an explanation of what a module is and how is used, thats a very different thing:
Modules are similar to classes in other languages, and are used to structure code cleanly;
defmodule
is just a language macro for defining a module.I would strong recommend going through elixirschool.com/en/lessons/basics... from scratch if you are fairly new to the language or programming in general.
I'll start soon to Elixir, btw thanks.
Thanks!