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

Ivan Carmenates Garcia <>
Sat Oct 10 20:49:25 CEST 2015


Even if you use atoms in many functions for pattern matching you won't be
using as many as for break down the system or consume the default maximum of
atoms allowed by the system. So use them freely in that way, warning a thing
you definably must never do is to use it as a conversion from a data that
comes from outside of Erlang or other context, for example never do this:

my_data_to_atom(StringData) when is_list(StringData) ->

This is a simple and pointless example but what I am trying to explain is
that StringData is an information that can vary in many ways and one you
make a new atom it will be never garbage collected so... unless you have
control of the StringData and know that it will be only a few constant
values of course.
Ivan (son of Gilberio).

-----Original Message-----
[mailto:] On Behalf Of Thomas Gebert
Sent: Saturday, October 10, 2015 11:46 AM
Subject: [erlang-questions] Why should you ever use atoms?

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

     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?

erlang-questions mailing list


More information about the erlang-questions mailing list