Home

Awesome

Catalog of Elixir-specific code smells

Run in Livebook

GitHub last commit Twitter URL

Table of Contents

Introduction

Elixir is a functional programming language whose popularity is rising in the industry <sup>link</sup>. However, there are few works in the scientific literature focused on studying the internal quality of systems implemented in this language.

In order to better understand the types of sub-optimal code structures that can harm the internal quality of Elixir systems, we scoured websites, blogs, forums, and videos (grey literature review), looking for specific code smells for Elixir that are discussed by its developers.

As a result of this investigation, we have initially proposed a catalog of 18 new smells that are specific to Elixir systems. After that, 1 new smell emerged from a study with mining software repositories (MSR) performed by us, and other smells are being suggested by the community, so this catalog is constantly being updated (currently 23 smells). These code smells are categorized into two different groups (design-related and low-level concerns), according to the type of impact and code extent they affect. This catalog of Elixir-specific code smells is presented below. Each code smell is documented using the following structure:

In addition to the Elixir-specific code smells, our catalog also documents 12 traditional code smells discussed in the context of Elixir systems.

The objective of this catalog of code smells is to instigate the improvement of the quality of code developed in Elixir. For this reason, we are interested in knowing Elixir's community opinion about these code smells: Do you agree that these code smells can be harmful? Have you seen any of them in production code? Do you have any suggestions about some Elixir-specific code smell not cataloged by us?...

Please feel free to make pull requests and suggestions (Issues tab). We want to hear from you!

▲ back to Index

Design-related smells

Design-related smells are more complex, affect a coarse-grained code element, and are therefore harder to detect. In this section, 14 different smells classified as design-related are explained and exemplified:

GenServer Envy

▲ back to Index


Agent Obsession

▲ back to Index


Unsupervised process

▲ back to Index


Large messages

▲ back to Index


Unrelated multi-clause function

▲ back to Index


Complex extractions in clauses

▲ back to Index


Using exceptions for control-flow

▲ back to Index


Untested polymorphic behaviors

▲ back to Index


Code organization by process

▲ back to Index


Large code generation by macros

▲ back to Index


Data manipulation by migration

▲ back to Index


Using App Configuration for libraries

▲ back to Index


Compile-time global configuration

▲ back to Index


"Use" instead of "import"

▲ back to Index

Low-level concerns smells

Low-level concerns smells are more simple than design-related smells and affect a small part of the code. Next, all 9 different smells classified as low-level concerns are explained and exemplified:

Working with invalid data

▲ back to Index


Complex branching

▲ back to Index


Complex else clauses in with

▲ back to Index


Alternative return types

▲ back to Index


Accessing non-existent Map/Struct fields

▲ back to Index


Speculative Assumptions

▲ back to Index


Modules with identical names

▲ back to Index


Unnecessary macros

▲ back to Index


Dynamic atom creation

▲ back to Index

About

This catalog was proposed by Lucas Vegi and Marco Tulio Valente, from ASERG/DCC/UFMG.

For more info see the following paper:

Please feel free to make pull requests and suggestions (Issues tab).

▲ back to Index

Acknowledgments

We are supported by Finbits<sup>TM</sup>, a Brazilian Elixir-based fintech:

<div align="center"> <a href="https://www.finbits.com.br/" alt="Click to learn more about Finbits!" title="Click to learn more about Finbits!"><img width="20%" src="https://github.com/lucasvegi/Elixir-Code-Smells/blob/main/etc/finbits.png?raw=true"></a> <br><br> </div>

Our research is also part of the initiative called Research with Elixir (in portuguese).

▲ back to Index

<!-- Links -->

Footnotes

  1. These code smells were suggested by the Elixir community. 2 3 4

  2. This code smell emerged from a study with mining software repositories (MSR).