DEV Community

Discussion on: What does Elixir defmodule actually?

Collapse
 
allanmacgregor profile image
Allan MacGregor 🇨🇦

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

module Dog 
   def talk
      puts "Woof!"
   end
end 

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.

Thread Thread
 
lyfolos profile image
Muhammed H. Alkan

I'll start soon to Elixir, btw thanks.