I am a huge fan of improving development workflows. The less I have to think about incidental things, the more I can concentrate on the problems that matter. One talk from ElixirConf 2022 helped improve my development workflow.

Jason Axelson doled out some essential tips to speed up Elixir development. A few quick wins for me included setting the ELIXIR_EDITOR and ERL_AFLAGS environment variables. Setting ELIXIR_EDITOR to your favorite editor allows you to quickly open module and function definitions for a given library or Elixir itself in your favorite editor from iex.

Visual Studio Code

export ELIXIR_EDITOR="code --goto __FILE__:__LINE__"

Emacs

export ELIXIR_EDITOR="emacs +__LINE__ __FILE__"

 

Once you have your favorite editor setup, you can start opening and exploring the code. This is a great way to learn and find out more when you are stuck on a problem outside of your application code.

iex(1)> open Phoenix.LiveView

When the ERL_AFLAGS environment variable is set you can search previously executed commands in iex across sessions. Without the ERL_AFLAGS set, you can only search the current iex session. The same keyboard shortcuts for your shell (bash is Ctrl+r). Instead of re-typing commands over and over, we can search and make a selection and re-run a command.

Shell

export ERL_AFLAGS="-kernel shell_history enabled"

 

Open iex and follow along.

iex(1)> IO.puts("Hello Binary Noggin")

Hello Binary Noggin

:ok

iex(2)> IO.inspect("Binary Noggin says hello")

"Binary Noggin says hello"

"Binary Noggin says hello"

iex(3)> # Ctrl+r and type puts. If you  This will look like the below replacing iex(3)>. Now hit ~enter~ and it'll choose the ~IO.puts~ command we executed. Now we can make changes or re-execute by hitting the ~enter~ key.

(search)`puts': IO.puts("Hello World")

 

I also learned about the library ExSync for Elixir code recompiling and reloading. I have added this to my workflow so I can get non-Phoenix applications to be rebuilt on code changes. Try out ExSync by adding the below to your mix.exs dependencies. It is really useful when you are developing a library and want to play around with it in iex and have it reload between changes.

{:exsync, "~> 0.2", only: :dev}

 

These tips have sped up my development processes, but Jason has many more. You can find those on Jason's slides.

Ingenious solutions in your inbox

Ingenious solutions in your inbox

Join our monthly newsletter list and be the first to learn about the latest blogs, events, and more!

You have Successfully Subscribed!