What Code Formatters Are Available For Erlang?

9 minutes read

There are several code formatters available for Erlang that can help ensure consistent and readable code formatting. Some popular options include:

  1. erl_tidy: This code formatter is included with Erlang/OTP and is the official formatter provided by the Erlang/OTP team. It follows the standard Erlang coding conventions and can be run from the command line or integrated into editors for automatic code formatting.
  2. elixir: This is an Emacs-based Erlang code formatter that offers automatic indentation, auto-fill functionality, and various customizable formatting options. It supports both Erlang and Elixir syntax.
  3. erlang-mode: This is a built-in mode for Emacs that includes various code formatting capabilities. It offers automatic indentation, code highlighting, and navigation within Erlang source files. Although it doesn't have a dedicated formatter, it provides essential tools to enhance code readability.
  4. edib: This is a code formatter specifically designed for Erlang. It focuses on automatic indentation and proper line breaking to improve code structure and readability. It can be used both as a command-line tool and integrated into text editors like Vim.
  5. erlang-format: This is an independent code formatter for Erlang that aims to provide a tool similar to "gofmt" for Go programming language. It is supported by the Erlang community and can be integrated into various editors to automatically format Erlang source code.


These code formatters help developers adhere to consistent code style guidelines, improve code readability, and make collaboration and maintenance easier within Erlang projects.

Best Erlang Books to Read in 2024

1
Handbook of Neuroevolution Through Erlang

Rating is 5 out of 5

Handbook of Neuroevolution Through Erlang

2
Designing for Scalability with Erlang/OTP: Implement Robust, Fault-Tolerant Systems

Rating is 4.9 out of 5

Designing for Scalability with Erlang/OTP: Implement Robust, Fault-Tolerant Systems

3
Learn You Some Erlang for Great Good!: A Beginner's Guide

Rating is 4.8 out of 5

Learn You Some Erlang for Great Good!: A Beginner's Guide

4
Erlang Programming: A Concurrent Approach to Software Development

Rating is 4.7 out of 5

Erlang Programming: A Concurrent Approach to Software Development

5
Programming Erlang: Software for a Concurrent World

Rating is 4.6 out of 5

Programming Erlang: Software for a Concurrent World

6
Erlang and OTP in Action

Rating is 4.5 out of 5

Erlang and OTP in Action

7
Erlang and Elixir for Imperative Programmers

Rating is 4.4 out of 5

Erlang and Elixir for Imperative Programmers

8
Property-Based Testing with PropEr, Erlang, and Elixir: Find Bugs Before Your Users Do

Rating is 4.3 out of 5

Property-Based Testing with PropEr, Erlang, and Elixir: Find Bugs Before Your Users Do


How to disable specific code formatting rules in Erlang?

In Erlang, code formatting rules are typically enforced using a tool called erlang-mode. To disable specific code formatting rules, you can modify the erlang-mode settings.


Here's how you can disable specific code formatting rules in Erlang:

  1. Open the .emacs file in your home directory using a text editor.
  2. Add the following line to the file to enable customization of erlang-mode settings: (custom-set-variables '(erlang-mode-code-indent-style "indent-tabs-mode")) Here, the erlang-mode-code-indent-style variable is set to "indent-tabs-mode" to use tabs for indentation. You can customize this variable according to your preference.
  3. Save the changes to the .emacs file.


By modifying the erlang-mode settings, you can disable specific code formatting rules or change the indentation style according to your needs.


What are the differences between code formatters for Erlang?

There are several code formatters available for Erlang, each with its own approach and set of features. Here are some of the main differences between popular code formatters for Erlang:

  1. Erlang's built-in code formatter (erl_prettypr): This is Erlang's default and often widely used code formatter. It follows the OTP-style layout conventions, which include indentation, line breaks, and column limits. However, it has limited customization options.
  2. erlang-mode in Emacs: Emacs offers an erlang-mode with built-in code formatting capabilities. It uses the erl_prettypr formatter by default, but you can configure it to other third-party formatters if desired. erlang-mode provides greater flexibility in customization through Emacs configuration.
  3. Elixir's formatter (mix format): Although primarily designed for Elixir, mix format can be used for formatting Erlang code as well. It has a different set of formatting guidelines compared to erl_prettypr, focusing on community-driven standards. It provides a more opinionated and automatic formatting approach.
  4. Tidy Erlang: Tidy Erlang is a standalone code formatter that offers precise control over code formatting rules. It allows you to define custom rules and can be integrated into various text editors or build systems. Tidy Erlang is highly flexible and allows you to achieve a highly tailored code formatting style.
  5. Elive: Elive is a code formatter for Erlang that aims to provide comprehensive and customizable code formatting options. It offers a wide range of formatting rules and can be configured to adhere to specific code style preferences.


It is important to note that the choice of code formatter depends on personal preferences, project guidelines, and the existing development environment/IDE being used.


How to enforce a specific code formatting style in Erlang?

There are a few ways to enforce a specific code formatting style in Erlang:

  1. Editor or IDE plugins: Use plugins like erlang-mode for Emacs, erlang-atom for Atom, or Erlide for Eclipse. These plugins often provide automatic formatting options that adhere to specified style guidelines.
  2. Linter tools: Utilize linter tools such as Dialyzer, EUnit, or Elint. These tools can analyze the code and give suggestions or enforce formatting rules based on predefined configurations.
  3. Build tools: Incorporate code formatting rules into your build process using tools like rebar3 or mix. Configure these tools to automatically format Erlang code during the build process, ensuring adherence to specific formatting guidelines.
  4. Custom scripts: Write custom scripts using Erlang's built-in tools such as erl_tidy or erlc to automatically format code. These scripts can be integrated into your workflow or build process to enforce consistent code formatting.
  5. Style checkers: Employ style checker libraries such as elvis, erlang-style-guide, or tidier. These libraries provide predefined style rules and can perform automatic checks against your codebase, flagging any deviations from the specified style.


Regardless of the method chosen, it is essential to establish clear and well-defined code formatting guidelines for your Erlang project and communicate them to the development team.

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

Related Posts:

To set two time formatters in matplotlib, you can create two instances of the DateFormatter class with different date format strings, and then use them to format the tick labels on the x-axis of your plot. First, instantiate the DateFormatter class twice with ...
Erlang is a programming language that has gained popularity for developing scalable and fault-tolerant systems, including web applications. When it comes to web development, Erlang offers several frameworks and libraries that facilitate the process. Here is an...
To install Erlang on Windows, follow these steps:Visit the official Erlang website at www.erlang.org.Go to the "Download" section of the website.Choose the Windows option under the "OTP" (Open Telecom Platform) category.Select the latest versio...
To send and receive messages between Erlang processes, you can use the message-passing mechanism provided by the Erlang programming language. Here are the key points to understand:Process Identification: In Erlang, processes are identified by a unique process ...
To configure Docker to expose an Erlang node, you need to follow these steps:Create a Dockerfile: First, create a Dockerfile in your project directory. This file will specify the base image, dependencies, and configurations for your Docker container. Choose an...
Working with binary data in Erlang allows for efficient manipulation and processing of binary data structures. Erlang provides a set of built-in functions and syntax for working with binary data. Here are some important aspects of working with binary data in E...