Getting Started With Elixir

4 things I wish I would have known when first working with Elixir. Typically, the first thing a developer working in a new language needs to get right is workflow. We need to create the quickest feedback loop as possible to maximize our productivity.



  1. Awesome Resouces: ElixirSips, Thoughtbot's blog, posts published on Medium, read the docs
  2. IEx Pry
  3. The i-helper
  4. Module.__info__(:functions)

Full Feature

So you started playing with the Elixir language. Congrats! It's pretty awesome. Jose Valim is a boss.

I'm assuming that at this point, you've downloaded Elixir/Erlang and can run a program. If not, follow that tutorial here and phoenix here to get started.

You're still here, eh? Alright, let's fire up our example program to get started.

Let's first set up an Elixir project - specifically a phoenix app so I can make my tips more meaningful:

$ mix example_project
$ cd example_project/
$ mix phoenix.gen.model User users name age:integer # create users DB table & model
$ <open your editor of choice>

OK cool, now let's introduce our helpful tips for Elixir noobs.

Tip #1 - Learning Resources

  1. Subscribe and Watch ElixirSips

It's fantastic and very similar to railscasts if you're familiar. The episodes are easily digestible (~10 minutes each), approachable (everything from data types, modules, OTP, etc.), and generally well done. At $10 a month, it's well worth the money.

  1. Thoughtbot's blog
  2. Medium's blog
  3. Read the docs

Tip #2 - IEx Pry

First, to make sure the DB connection doesn't timeout while running our tests, we're going to bump the ownership timeout of our app while in the test env.

# config/test.exs

# Configure your database
config :my_app, MyApp.Repo,
  # ...
  ownership_timeout: 9_000_000

Next, open test/models/user_test.exs which should have been generated for you with the mix phoenix.gen.model User users name age:integer command run above. Let's require IEx near the top of our file, and place an IEx.pry in the first test. Additionally, you'll notice a @tag :focus above the test I want to focus on - this could be considered helpful tip #2.5.

Run the test with an iex session (Elixir’s interactive shell) to jump into a breakpoint and inspect the code. Note, the --trace option is important not to lose your DB connection while in the iex shell - it will timeout otherwise.

$ iex -S mix test --only focus --trace
defmodule ExampleProject.UserTest do
  use ExampleProject.ModelCase

  alias ExampleProject.User

  require IEx

  @valid_attrs %{age: 42, name: "some content"}
  @invalid_attrs %{}

  @tag :focus
  test "changeset with valid attributes" do
    changeset = User.changeset(%User{}, @valid_attrs)
    assert changeset.valid?

  test "changeset with invalid attributes" do
    changeset = User.changeset(%User{}, @invalid_attrs)
    refute changeset.valid?

You can now inspect any variables in your test. IEx works in controllers and models very well, but I haven't had much success in views FWIW. To continue on and finish your test, enter respawn().

Tip #3 - the i-helper

OK, I'm going to play off of tip #2 with this one. Still in the same IEx session, inspect changeset with i changeset. You should see something similar to:

Whoa... this is pretty awesome. It describes the object with almost everything you need to know. It provides the data type, the reference modules, and implemented protocols.

Let's take this a step further. Say I wanted to inspect the source of a Ecto.Changeset data type. The i helper makes that super easy.

Run the i-helper on the Module:

$ i Ecto.Changeset

Hey, this is also super awesome. I can now follow the Source path in my editor to inspect the module.

Now that I know what data type and modules to work on the changeset, how can I figure out what functions to call on the object? Well, that brings me to helpful tip #4.

Tip #4 - Module.__info__(:functions)

Still in your IEx session, type out the following commands to figure out what Module functions are at your disposal to work with the changeset. Since an Ecto.Changeset references


Since ecto changesets also reference the Map module, let's check out those too:



If you have any recommendations for helpful elixir commands, tools, etc. please feel free to drop a comment below. I would love to hear from you and would love another elixir tool in the ol' tool belt.

Happy coding!