Code Smells in Elixir: Early Results from a Grey Literature Review

A preprint of a paper by Lucas Francisco da Matta Vegi and Marco Tulio Valente has been published:

Elixir is a new functional programming language whose popularity is rising in the industry. However, there are few works in the literature focused on studying the internal quality of systems implemented in this language. Particularly, to the best of our knowledge, there is currently no catalog of code smells for Elixir. Therefore, in this paper, through a grey literature review, we investigate whether Elixir developers discuss code smells. Our preliminary results indicate that 11 of the 22 traditional code smells cataloged by Fowler and Beck are discussed by Elixir developers. We also propose a list of 18 new smells specific for Elixir systems and investigate whether these smells are currently identified by Credo, a well-known static code analysis tool for Elixir. We conclude that only two traditional code smells and one Elixir-specific code smell are automatically detected by this tool. Thus, these early results represent an opportunity for extending tools such as Credo to detect code smells and then contribute to improving the internal quality of Elixir systems.

Comments are welcome!

14 Likes

An early note as I’m reading - I don’t believe “exceptions for control-flow” is an Elixir-specific smell; for instance, the C2 Wiki has examples in C++, Java, and Python.

2 Likes

More details and examples on Elixir-specific code smells are available at https://github.com/lucasvegi/Elixir-Code-Smells

6 Likes

I have recorded a video about a new feature of the Elixir Code Smells site:

A Livebook notebook for Elixir Code Smells

1 Like

The paper was finally presented at the 30th IEEE/ACM International Conference on Program Comprehension (ICPC 2022). The presentation has only 4 minutes long and is available on YouTube (subtitles in English and Brazilian Portuguese).

https://youtu.be/3X2gxg13tXo

I wonder if during your research you found something that makes the lines a little less blurry around what comprises a “code smell” or “anti-pattern” in a functional language. From what I’ve read so far (not this research in particular), most of it seems to suggest personal preferences/approaches to code structuring and organization.

It’s hard for me to make the correlation because “code smells” in OOP usually reveal abstraction problems, and in FP land we only have one construct for that: functions.

I’d love to hear from other, more experienced members of the community and also from other, more mature FP communities about what “code smell” and “anti-pattern” means to them since this is already very debatable in OOP itself.

I personally like this talk about FP programming patterns, which was very valuable to me while migrating over from OOP languages to Elixir:

3 Likes

Hi Thiago,

it is really very motivating to explore the universe of code smells in functional languages ​​because this is a universe that has practically only been explored/researched for the object-oriented paradigm. In functional programming, it is still a “blank notebook”.

It is among our goals to catalog smells that are characteristic of the functional paradigm, regardless of language. Something similar to what happens with the traditional smells cataloged by Fowler and Beck thinking about the object-oriented paradigm. Anyway, in order to achieve this ambitious goal, we chose to start exploring specific smells of functional languages ​​and then better understand if there is an intersection between them, thus arriving at paradigm smells. Elixir was our starting point, but we intend to increase our scope in the future, investigating Clojure, for example.

You are right when you say that there are many discussions about functional smells that reflect more personal programming preferences, code formatting issues, and other aspects that are easily circumvented by linters, but this is not our focus. We’ve already identified 22 specific smells for Elixir, 13 of which are related to design issues. I recommend that you take a leisurely look at our GitHub repository later. The next step of our research will be to listen to the most experienced developers of the language to understand better how often each of these smells appears in production code and the impact (severity) of each one of them.

In the future, we will have more news about it! Our research is just beginning. :blush:

1 Like