Part 2–Elixir for a PHP Developer

Kamaro Lambert
4 min readJul 20, 2023

--

1.0 Basics — Installation and iex Terminal

1.1 Quick Intro to Elixir

Welcome to the captivating world of Elixir, the very language that powers the renowned Phoenix framework. But before we dive into the magic of Phoenix, let’s take a quick detour and acquaint ourselves with the enchanting Elixir programming language. This overview is designed to set you on the fast track to mastery. Assuming you have experience with popular languages like PHP and Python, we’ll skip the basics of programming and delve straight into writing them in the fascinating realm of Elixir.

Pro tip: Prioritize the Basics

If you’re new to programming languages, don’t fret! We encourage you to grasp the fundamentals first. We will focus on demonstrating how to write variables and functions in Elixir, making your learning experience smooth and enjoyable.

1.1.2 Installing Elixir: The Gateway to a New World

To begin our journey, we must prepare your environment and install the Elixir programming language. An exciting tidbit: Elixir is like a sweet, sugary coating on top of the mighty Erlang, adding even more magic to the mix. Our installation process will handle both Erlang and Elixir, ensuring you’re all set to go!

Head over to https://elixir-lang.org/install.html, and select the installation that matches your operating system. Download, install, and follow the instructions to get the latest version tailored to your needs. Then, return to this page, and we’ll proceed to the next step.

Once installed, brace yourself for the wonders of Elixir! Open your terminal and type ‘iex’, then hit enter. Behold, a new world emerges before your eyes!

The iex Interactive Shell: Where Magic Happens

Now that you’re armed with Elixir’s interactive shell, akin to PHP’s php -a or Python’s python, let the practical exploration begin!

1.1.3 1.1.3 Handy Tips for Navigating the iex Terminal

As we delve into Elixir’s exciting potential, let’s learn some useful tips to make your journey even more enjoyable. Mastering the iex shell will empower you to unlock Elixir’s true magic.

Now that you are in the terminal, how do you come out? It’s right before you on the shell you just opened. All you need is to press Ctrl + C on your keyboard.

1.1.3.1 Instant Assistance: h() or h

Elixir has a wealth of documentation and is always ready to lend a helping hand. You'll discover a treasure trove of knowledge at your fingertips by simply typing h() or h in the terminal. The documentation and help options are available for you.

1.1.3.2 Delve Deeper: Getting Help for Specific Modules and Functions

The ‘h’ command doesn’t just stop at the iex helpers. Extend your understanding by requesting documentation for specific modules or functions. For instance, if you want to explore the DateTime module, just type ‘h DateTime’ and unveil its secrets.

1.1.3.3 Streamline Your Workflow: TAB Key Autocompletion

Need help remembering function names or parameters? Fear not! Elixir offers a handy solution. Start typing, then press the TAB key, and witness the magic of autocompletion. Effortlessly discover available modules and functions at your disposal.

The terminal displays options for available modules that match the Date. In this case, its Date and DateTime.

But what about seeing the available function under a module?

You type the module and proceed with it a dot(.), then press the TAB key. For instance, if you want to see available functions under DateTime, you can write DateTime. Press TAB, you will see all available functions.

Now that we know the available functions, we can call any. Type DateTime.utc_now()

You’re now well-equipped to conquer the fascinating world of Elixir and Phoenix. Get ready to create extraordinary applications as you embark on a journey of creativity and innovation like never before!

Today, we’ve covered the essentials of:

  1. Installing Elixir and embracing the power of Erlang
  2. Launching the iex Interactive Shell
  3. Tapping into Elixir’s documentation with ‘h()
  4. Navigating with ease using the TAB key for auto-completion

--

--

Kamaro Lambert

I write about principles to maximize your potential as an individual by sharing lessons from my experience and top 10% leaders. CTO