Today I Learned

This project exists to catalogue the sharing & accumulation of knowledge as it happens day-to-day. Posts have a 200-word limit, and posting is open to any Rocketeer as well as selected friends of JetRockets. We hope you enjoy learning along with us.

Elixir code formatting in IDE (with Atom set up example)

Today I learned that Elixir has a great feature that allows you to format your code.

Here are a few reasons you may want to do that (borrowed from The Go Blog):

  • easier to write: never worry about minor formatting concerns,
  • easier to read: when all code looks the same you need not mentally convert others’ formatting style into something you can understand.
  • easier to maintain: diffs show only the real changes.
  • uncontroversial: never have a debate about spacing or brace position ever again

In fact, you actually want to format your Elixir code as you make it, meaning there is no need to format all of your project’s code every time.

The following bash command does it well on a single file: cd $projectPath && mix format $filePath

Where: $projectPath - full path to your project’s root directory; $filePath - full path to a file you’re saving

My IDE of choice happened to be Atom and I’ll talk briefly on setting it up. The Process Palette package so far is the best for this task. My Shell Command field (with variables) in Process Palette looks the following cd {projectPath} && mix format {fileAbsPath}

Looking for help? Elixir is quickly gaining momentum for web applications that need concurrency, performance, and the ability to connect to many different clients. The developers at JetRockets are learning along with the rest of the development community that Elixir and Phoenix are viable Rails alternatives for the right application. Please contact us if you need help with your Elixir project.