# Permit coma before the enclosing \]

**URL:** <https://erlangforums.com/t/permit-coma-before-the-enclosing/4753>\
**Category:** Proposals: Ideas\
**Tags:** erlang-enhancement-proposals, erlang\
**Created:** [May 14, 2025, 9:23am UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753 "2025-05-14T09:23:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![meox](https://erlangforums.com/user_avatar/erlangforums.com/meox/32/476_2.png) [@meox](https://erlangforums.com/u/meox)\
**Post date:** [May 14, 2025, 9:23am UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/1 "2025-05-14T09:23:27Z")

</div>

I propose to make this kind of code legal:

```erlang
[
    element_a,
   element_b,
]

```

not the extra “,” before the enclosing of the `]` parenthesis.  
The same apply to map:

```erlang
#{
    a => 1,
   b => 2,
}

```

The main reason for me is to make easier messing up with the tests in the ct common test enabling/disabling it without having to specify the list of the test from the command line.

The other reason is that this allowed in language like Elixir so could be a little improvement to commonize this behavior.

---

<div class="post-metadata">

**Author:** ![garazdawi](https://erlangforums.com/user_avatar/erlangforums.com/garazdawi/32/175_2.png) [@garazdawi](https://erlangforums.com/u/garazdawi)\
**Post date:** [May 14, 2025, 10:35am UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/2 "2025-05-14T10:35:20Z")

</div>

> [@meox](#):
>
> The main reason for me is to make easier messing up with the tests in the ct common test enabling/disabling it without having to specify the list of the test from the command line.

While this is annoying for sure, I’m not sure it is enough to warrant an addition to the language. What other use cases are there?

[EEP-0021](https://www.erlang.org/eeps/eep-0021) from 2008 suggests the same things and the discussion around it is available on the old erlang-questions mailing list. I wasn’t around at that time so don’t know why it was not accepted, but the discussion tends to come up from time to time 🙂

---

<div class="post-metadata">

**Author:** ![meox](https://erlangforums.com/user_avatar/erlangforums.com/meox/32/476_2.png) [@meox](https://erlangforums.com/u/meox)\
**Post date:** [May 14, 2025, 11:25am UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/3 "2025-05-14T11:25:09Z")

</div>

Thanks a lot for point me in the right EEP.  
I think that there are these use cases:

- easily moving and grouping the record field or the exported functions without worrying about where is the coma
- easily moving deps in the rebar config
- easily commenting/decommenting tests on ct suite
- having the same behavior of Elixir

---

<div class="post-metadata">

**Author:** ![Timmo](https://erlangforums.com/user_avatar/erlangforums.com/timmo/32/2835_2.png) [@Timmo](https://erlangforums.com/u/Timmo)\
**Post date:** [May 14, 2025, 1:28pm UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/4 "2025-05-14T13:28:39Z")

</div>

Another use case is smaller diffs in some scenario’s, like updating deps in an app:

```erlang
- some_dep
+ some_dep,
+ new_dep

```

vs

```erlang
+ new_dep,

```

The benefit here is more concise diffs and no “unrelated” or “irrelevant” line-changes.

---

<div class="post-metadata">

**Author:** ![mikpe](https://erlangforums.com/letter_avatar_proxy/v4/letter/m/b487fb/32.png) [@mikpe](https://erlangforums.com/u/mikpe)\
**Post date:** [May 14, 2025, 1:48pm UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/5 "2025-05-14T13:48:02Z")

</div>

Ah the old separator-vs-terminator discussion.

Some or us adapt a comma-first convention which gives most of the same benefits as allowing a trailing separator before the closing symbol.

---

<div class="post-metadata">

**Author:** ![meox](https://erlangforums.com/user_avatar/erlangforums.com/meox/32/476_2.png) [@meox](https://erlangforums.com/u/meox)\
**Post date:** [May 14, 2025, 1:56pm UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/6 "2025-05-14T13:56:22Z")

</div>

if you mean:

```erlang
[
a
, b
, c
]

```

you still have a special case: the first element of the list (the `a`)

---

<div class="post-metadata">

**Author:** ![Timmo](https://erlangforums.com/user_avatar/erlangforums.com/timmo/32/2835_2.png) [@Timmo](https://erlangforums.com/u/Timmo)\
**Post date:** [May 14, 2025, 2:07pm UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/7 "2025-05-14T14:07:16Z")

</div>

If your list is

```erlang
[
 b
 , c
]

```

Adding `a` would give you a diff like

```erlang
- b
+ a
+ , b

```

Or, if you’re a psychopath 😉

```erlang
+ , a

```

However those of us who use erlfmt are not getting into the separator-vs-terminator discussion 😄

---

<div class="post-metadata">

**Author:** ![elbrujohalcon](https://erlangforums.com/user_avatar/erlangforums.com/elbrujohalcon/32/241_2.png) [@elbrujohalcon](https://erlangforums.com/u/elbrujohalcon)\
**Post date:** [May 14, 2025, 2:53pm UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/8 "2025-05-14T14:53:54Z")

</div>

> [@Timmo](#):
>
> However those of us who use erlfmt are not getting into the separator-vs-terminator discussion 😄

From my perspective (also a comma-first fan, but also an erlfmt user), this is the most relevant reason to permit trailing commas in list-y things: To avoid using a _hack_ in the formatter to deal with them producing code that’s not exactly what I wrote.

In other words, I want to use `erlfmt` without being surprised by it _changing_ my code (beyond formatting it, of course) when I run it. If trailing commas were allowed by the language, there would be no reason for `erlfmt` to remove them from my code 🙂

---

<div class="post-metadata">

**Author:** ![nzok](https://erlangforums.com/letter_avatar_proxy/v4/letter/n/4af34b/32.png) [@nzok](https://erlangforums.com/u/nzok)\
**Post date:** [May 15, 2025, 6:16am UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/9 "2025-05-15T06:16:14Z")

</div>

As noted, this was raised back in 2008. I find the argument from Elixir has more weight for Erlang than the argument from Python. Or it would if I found Elixir syntax less repugnant. Rebar didn’t exist back then. And there have been much bigger additions to Erlang syntax since. Perhaps it is time to revisit this topic.

By the way, I really don’t want any comas when dealing with Erlang. Commas are Ok, but no comas.

---

<div class="post-metadata">

**Author:** ![eproxus](https://erlangforums.com/user_avatar/erlangforums.com/eproxus/32/452_2.png) [@eproxus](https://erlangforums.com/u/eproxus)\
**Post date:** [May 15, 2025, 6:32pm UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/10 "2025-05-15T18:32:27Z")

</div>

_Poll ([view on site](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/10))_

---

<div class="post-metadata">

**Author:** ![carlotm](https://erlangforums.com/user_avatar/erlangforums.com/carlotm/32/1870_2.png) [@carlotm](https://erlangforums.com/u/carlotm)\
**Post date:** [May 16, 2025, 6:39am UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/11 "2025-05-16T06:39:39Z")

</div>

> [@meox](#):
>
> The other reason is that this allowed in language like Elixir so could be a little improvement to commonize this behavior.

Last time I checked, the official Elixir formatter removed trailing commas,  
and it was not configurable.

Maybe that’s not the case anymore though.

---

<div class="post-metadata">

**Author:** ![eproxus](https://erlangforums.com/user_avatar/erlangforums.com/eproxus/32/452_2.png) [@eproxus](https://erlangforums.com/u/eproxus)\
**Post date:** [May 16, 2025, 12:15pm UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/12 "2025-05-16T12:15:29Z")

</div>

If trailing commas were supported, I feel the best default would be to add them as lines could then be moved/deleted at any position with the benefits mentioned above.

I think it would be hard/impossible to make a formatter automatically add commas in the middle if e.g. the last line without comma was moved earlier in a list.

Whereas it is always safe to add a trailing comma if one is missing.

---

<div class="post-metadata">

**Author:** ![vances](https://erlangforums.com/user_avatar/erlangforums.com/vances/32/710_2.png) [@vances](https://erlangforums.com/u/vances)\
**Post date:** [May 16, 2025, 12:38pm UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/13 "2025-05-16T12:38:11Z")

</div>

Some like commas first so we should support extra leading commas too. Also if a mix of trailing comma and leading comma is encountered that should be OK too. So really just any mixed bag of commas and whitespace would be OK. That way lies madness.

---

<div class="post-metadata">

**Author:** ![meox](https://erlangforums.com/user_avatar/erlangforums.com/meox/32/476_2.png) [@meox](https://erlangforums.com/u/meox)\
**Post date:** [May 16, 2025, 12:39pm UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/14 "2025-05-16T12:39:34Z")

</div>

commas first are just an hack because u don’t have the trailing one 😉

---

<div class="post-metadata">

**Author:** ![Maria-12648430](https://erlangforums.com/user_avatar/erlangforums.com/maria-12648430/32/604_2.png) [@Maria-12648430](https://erlangforums.com/u/Maria-12648430)\
**Post date:** [May 16, 2025, 3:41pm UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/15 "2025-05-16T15:41:14Z")

</div>

Just my $0.02…

I’m not a fan of allowing trailing commas really, but I wouldn’t mind too much either. I just wouldn’t use them, that is I like my code _tidy_ 😉

However, the same case that would justify trailing commas could be made for `function`/`case`/`if` clauses and the semicolon. And allowing trailing _semicolons_ I would _definitely_ object to.

---

<div class="post-metadata">

**Author:** ![juhlig](https://erlangforums.com/user_avatar/erlangforums.com/juhlig/32/837_2.png) [@juhlig](https://erlangforums.com/u/juhlig)\
**Post date:** [May 16, 2025, 3:56pm UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/16 "2025-05-16T15:56:06Z")

</div>

I didn’t like the trailing commas idea to begin with, and now you have given me nightmares with trailing semicolons in them… Thanks @Maria-12648430 🤪

---

<div class="post-metadata">

**Author:** ![Maria-12648430](https://erlangforums.com/user_avatar/erlangforums.com/maria-12648430/32/604_2.png) [@Maria-12648430](https://erlangforums.com/u/Maria-12648430)\
**Post date:** [May 16, 2025, 5:17pm UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/17 "2025-05-16T17:17:48Z")

</div>

My pleasure, be my guest 😁

---

<div class="post-metadata">

**Author:** ![eproxus](https://erlangforums.com/user_avatar/erlangforums.com/eproxus/32/452_2.png) [@eproxus](https://erlangforums.com/u/eproxus)\
**Post date:** [May 17, 2025, 7:45am UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/18 "2025-05-17T07:45:49Z")

</div>

If they get added I think it would make most sense to only add them to all ”collections”, i.e. lists, maps, tuples and records.

I too wouldn’t want them for expressions (even though the same argument could be made there as well of course).

---

<div class="post-metadata">

**Author:** ![AstonJ](https://erlangforums.com/user_avatar/erlangforums.com/astonj/32/9_2.png) [@AstonJ](https://erlangforums.com/u/AstonJ)\
**Post date:** [May 17, 2025, 2:11pm UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/19 "2025-05-17T14:11:27Z")

</div>

> [@carlotm](#):
>
> Last time I checked, the official Elixir formatter removed trailing commas,  
> and it was not configurable.
> 
> Maybe that’s not the case anymore though.

I was about to say the same. I actually posted a thread about this on EF a while back:

> **[Do you always add a trailing comma?](https://elixirforum.com/t/do-you-always-add-a-trailing-comma/21156)**
>
> EG: defp deps do \[{:phoenix, "~\> 1.4.1"}, {:phoenix\_pubsub, "~\> 1.1"}, {:phoenix\_ecto, "~\> 4.0"}, \] end Or do you prefer not to? defp deps do \[ {:phoenix, "~\> 1.4.1"}, ...

---

<div class="post-metadata">

**Author:** ![arcanemachine](https://erlangforums.com/user_avatar/erlangforums.com/arcanemachine/32/2503_2.png) [@arcanemachine](https://erlangforums.com/u/arcanemachine)\
**Post date:** [May 17, 2025, 9:43pm UTC](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753/20 "2025-05-17T21:43:00Z")

</div>

(I’m primarily an Elixir developer so I don’t know if my understanding of the situation carries over to Erlang.)

I’m not here to extol the virtues of Javascript, but they did get one thing very right by allowing _optional_ trailing commas.

As mentioned by others, this allows for simplified diffs, but one major benefit IMO is that some of the auto-formatters (e.g. Prettier) allow the trailing comma to be used to define how a (short) list of items is formatted.

Given a short list of items:

`[1, 2, 3].`

If a trailing comma is placed at the end of a list, e.g.:

`[1, 2, 3,].`

Then the formatter will automatically split it into multiple lines when it is applied (e.g. on save, if auto-format-on-save is enabled):

```erlang
[
  1,
  2,
  3,
].

```

(This looks silly for a short list like this, but it demonstrates the point. It is nice to use for more complex data structures.)

Conversely, if the trailing comma is removed, then _shorter_ lines will automatically be merged back to a single line. _Longer_ lines will be split into multiple lines as needed (to maintain the configured max line length), and will have the trailing comma, as one would expect.

This feature is nested as well, so you have the ability to determine which structures can be placed on one line, and which should be split up into multiple lines:

```erlang
[
  #{hello => world, goodbye => troubles},
  #{
    hello => world,
    goodbye => troubles,
  },
].

```

It’s a small syntactic difference that can lead to _much_ more readable code, IMO.

@carlotm Elixir removes trailing commas by default (a mistake IMO, as it precludes the ability to apply the aforementioned formatter trick), but there is a custom formatter called [Freedom Formatter](https://github.com/marcandre/freedom_formatter) which apparently implements this feature. (I have not used it myself since I prefer to stick to conventional code styles when possible, even if I prefer the customization.)

[Next page](https://erlangforums.com/t/permit-coma-before-the-enclosing/4753.md?page=2)
