<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged mix</title>
<link>https://coderlegion.com/tag/mix</link>
<description>Powered by Question2Answer</description>
<item>
<title>Getting Started with Elixir: Understanding Erlang, BEAM, and Your First Mix Project</title>
<link>https://coderlegion.com/10308/getting-started-with-elixir-understanding-erlang-beam-and-your-first-mix-project</link>
<description>&lt;h3 id=&quot;introduction&quot;&gt;Introduction&lt;/h3&gt;
&lt;p&gt;In the previous article, we covered how to set up the development environment to start working with Elixir.&lt;br&gt;
Now it’s time to talk about the language itself and write our first real code.&lt;/p&gt;
&lt;p&gt;If you are coming from languages like JavaScript, Ruby, or Python, some concepts may feel unfamiliar at first — and that’s totally normal.&lt;/p&gt;
&lt;p&gt;Let’s start by understanding why we had to install both &lt;strong&gt;Elixir and Erlang&lt;/strong&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;elixir-vs-erlang&quot;&gt;Elixir vs Erlang&lt;/h3&gt;
&lt;p&gt;Erlang is a programming language created decades ago to solve problems related to &lt;strong&gt;telecommunication systems&lt;/strong&gt;, such as reliability, concurrency, and fault tolerance.&lt;/p&gt;
&lt;p&gt;It is extremely powerful, but its syntax is considered quite complex for many developers.&lt;/p&gt;
&lt;p&gt;This is where Elixir comes in.&lt;/p&gt;
&lt;p&gt;Elixir provides a &lt;strong&gt;modern and friendly syntax&lt;/strong&gt;, while still running on top of the same runtime as Erlang.&lt;br&gt;
In practice, your Elixir code is compiled to Erlang bytecode and executed by the same virtual machine.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-is-beam-&quot;&gt;What is BEAM?&lt;/h3&gt;
&lt;p&gt;BEAM stands for &lt;strong&gt;Bogdan/Björn’s Erlang Abstract Machine&lt;/strong&gt;, named after its original creators.&lt;/p&gt;
&lt;p&gt;It is the virtual machine responsible for running Erlang and Elixir code, similar to how the JVM runs Java and Kotlin.&lt;/p&gt;
&lt;p&gt;BEAM is famous for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Lightweight processes  &lt;/li&gt;
&lt;li&gt;Massive concurrency  &lt;/li&gt;
&lt;li&gt;Fault-tolerant design  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is one of the main reasons Elixir is used in systems that require high availability.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;creating-your-first-project-with-mix&quot;&gt;Creating Your First Project with Mix&lt;/h3&gt;
&lt;p&gt;The best way to learn a programming language is by building something.&lt;/p&gt;
&lt;p&gt;Reading documentation and watching tutorials helps, but real learning happens when you actually write code.&lt;/p&gt;
&lt;p&gt;In Elixir, we use &lt;strong&gt;Mix&lt;/strong&gt;, the built-in build tool and project manager.&lt;/p&gt;
&lt;p&gt;Mix is responsible for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Creating projects  &lt;/li&gt;
&lt;li&gt;Compiling code  &lt;/li&gt;
&lt;li&gt;Managing dependencies  &lt;/li&gt;
&lt;li&gt;Running tasks and tests  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let’s create a new project.&lt;/p&gt;
&lt;p&gt;In your terminal, run:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;mix new basics
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You should see an output similar to:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/basics.ex
* creating test
* creating test/test_helper.exs
* creating test/basics_test.exs
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now enter the project directory:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;cd basics
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h3 id=&quot;modules-and-functions&quot;&gt;Modules and Functions&lt;/h3&gt;
&lt;p&gt;Inside the &lt;code&gt;lib&lt;/code&gt; directory, you will find the file &lt;code&gt;basics.ex&lt;/code&gt; with the following content:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-elixir&quot;&gt;defmodule Basics do
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In Elixir, almost all code lives inside &lt;strong&gt;modules&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;A module is simply a &lt;strong&gt;collection of functions&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Let’s add our first function:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-elixir&quot;&gt;defmodule Basics do
  def create_list do
    [1, 2, 3, &quot;little indians&quot;]
  end
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We use &lt;code&gt;def&lt;/code&gt; to define a function inside the &lt;code&gt;Basics&lt;/code&gt; module.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;running-the-project-with-iex&quot;&gt;Running the Project with IEx&lt;/h3&gt;
&lt;p&gt;To run and test our code, we use &lt;strong&gt;IEx (Interactive Elixir Shell)&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;It works like Python’s REPL or Ruby’s IRB, allowing you to run Elixir code interactively.&lt;/p&gt;
&lt;p&gt;From the project directory, run:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;iex -S mix
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now test the function:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-elixir&quot;&gt;Basics.create_list()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You should get:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-elixir&quot;&gt;[1, 2, 3, &quot;little indians&quot;]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice that the last expression is automatically returned.&lt;br&gt;
This is called &lt;strong&gt;implicit return&lt;/strong&gt;, which is common in functional programming.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;object-oriented-vs-functional-programming&quot;&gt;Object-Oriented vs Functional Programming&lt;/h3&gt;
&lt;p&gt;In object-oriented languages, you usually create objects and call methods on them.&lt;/p&gt;
&lt;p&gt;In functional programming, functions return values directly without relying on object instances.&lt;/p&gt;
&lt;p&gt;In Elixir:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;There are no classes  &lt;/li&gt;
&lt;li&gt;Modules are not objects  &lt;/li&gt;
&lt;li&gt;Functions return data  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A module is just a namespace for functions, nothing more.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;understanding-arity&quot;&gt;Understanding Arity&lt;/h3&gt;
&lt;p&gt;In Elixir, functions are identified not only by their name, but also by the &lt;strong&gt;number of arguments&lt;/strong&gt; they receive.&lt;/p&gt;
&lt;p&gt;This is called &lt;strong&gt;arity&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Let’s create a new function:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-elixir&quot;&gt;def shuffle(list) do
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now recompile inside IEx:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-elixir&quot;&gt;recompile
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And try calling:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-elixir&quot;&gt;Basics.shuffle()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You will see an error similar to:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-text&quot;&gt;function Basics.shuffle/0 is undefined. Did you mean shuffle/1?
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That means the function expects &lt;strong&gt;one argument&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-elixir&quot;&gt;defmodule Basics do
  def hello(), do: &quot;Hello World&quot;            # hello/0
  def hello(name), do: &quot;Hello, #{name}&quot;    # hello/1
  def hello(a, b), do: &quot;#{a} and #{b}&quot;      # hello/2
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These are considered &lt;strong&gt;different functions&lt;/strong&gt; because of their arity.&lt;/p&gt;
&lt;p&gt;Arity is written as:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;function_name/number_of_arguments
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It becomes very important later when working with pattern matching and function clauses.&lt;/p&gt;
&lt;p&gt;More about functions and arity:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://elixirschool.com/en/lessons/basics/functions/&quot;&gt;https://elixirschool.com/en/lessons/basics/functions/&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;In this article we covered:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The relationship between Elixir and Erlang  &lt;/li&gt;
&lt;li&gt;What BEAM is and why it matters  &lt;/li&gt;
&lt;li&gt;How to create projects with Mix  &lt;/li&gt;
&lt;li&gt;How modules and functions work  &lt;/li&gt;
&lt;li&gt;What function arity means  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In the next article, we’ll continue improving this project and exploring more Elixir features.&lt;/p&gt;
&lt;p&gt;See you soon!&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/10308/getting-started-with-elixir-understanding-erlang-beam-and-your-first-mix-project</guid>
<pubDate>Thu, 22 Jan 2026 23:35:11 +0000</pubDate>
</item>
</channel>
</rss>