[erlang-questions] Why should you ever use atoms?

Pierpaolo Bernardi <>
Sat Oct 10 18:00:51 CEST 2015

On Sat, Oct 10, 2015 at 5:46 PM, Thomas Gebert <> wrote:
> I know this is probably kind of a newbie question, but I figured this would
> be the place to ask it: if atoms aren't garbage collected, why should I use
> them? For example, it's a common pattern to have something like:
>     myFunction({user, "tombert","eats pizza"}) -> %% do something
> When I could easily do something like:
>     myFunction({"user", "tombert", "eats pizza"}) -> %% do something
> ----
> I could be way off here, but wouldn't the string be garbage collected?  Is
> there a benefit to atoms that I'm missing?

Yes. Atoms can be checked for identity with one machine instruction,
while strings need to be scanned.

More information about the erlang-questions mailing list