Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/elixir/pages/anti-patterns/code-anti-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ end

#### Problem

An `Atom` is an Elixir basic type whose value is its own name. Atoms are often useful to identify resources or express the state, or result, of an operation. Creating atoms dynamically is not an anti-pattern by itself. However, atoms are not garbage collected by the Erlang Virtual Machine, so values of this type live in memory during a software's entire execution lifetime. The Erlang VM limits the number of atoms that can exist in an application by default to *1_048_576*, which is more than enough to cover all atoms defined in a program, but attempts to serve as an early limit for applications which are "leaking atoms" through dynamic creation.
An `Atom` is an Elixir basic type whose value is its own name. Atoms are often useful to identify resources or express the state, or result, of an operation. Creating atoms dynamically is not an anti-pattern by itself. However, atoms are not garbage collected by the Erlang Virtual Machine, so values of this type live in memory during a software's entire execution lifetime. The Erlang VM limits the number of atoms that can exist in an application by default to *1,048,576*, which is more than enough to cover all atoms defined in a program, but attempts to serve as an early limit for applications which are "leaking atoms" through dynamic creation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that commas are locale specific. Not all languages and location use the same. For example, in Brazil, we would use dots. Perhaps we do `1_048_576` and have it show up as actual code, as in the other PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the documentation is written in English language. I would say along with the white-space separator is the most common in English speaking countries.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Language and localization are two different things. Assuming people speak english is one thing but assuming they are all in a certain locale is another. But without going into this whole discussion, let's ask this instead:

  1. Do we use this convention anywhere else in the codebase?
  2. Why not use 1_048_576 is would be unambiguous for Elixir developers regaradless of their locale?

Copy link
Contributor Author

@eksperimental eksperimental Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use it only here:

lib/elixir/lib/calendar/time.ex
784:  Gregorian calendar that adds exactly 10,000 years to the current Gregorian
840:  Gregorian calendar that adds exactly 10,000 years to the current Gregorian

lib/elixir/lib/calendar/date.ex
636:  Gregorian calendar that adds exactly 10,000 years to the current Gregorian
670:  Gregorian calendar that adds exactly 10,000 years to the current Gregorian

lib/elixir/lib/calendar/datetime.ex
1925:  Gregorian calendar that adds exactly 10,000 years to the current Gregorian
1972:  Gregorian calendar that adds exactly 10,000 years to the current Gregorian

lib/elixir/lib/calendar/naive_datetime.ex
1264:  Gregorian calendar that adds exactly 10,000 years to the current Gregorian
1330:  Gregorian calendar that adds exactly 10,000 years to the current Gregorian

Using 1_048_576 works in this case because it is not an introductory material, but given the case of someone new to Elixir reading this, I don't think _ would mean much.

I'm OK with using 1_048_576, but I think it is something to think about.


For these reasons, creating atoms dynamically can be considered an anti-pattern when the developer has no control over how many atoms will be created during the software execution. This unpredictable scenario can expose the software to unexpected behavior caused by excessive memory usage, or even by reaching the maximum number of *atoms* possible.

Expand Down