Capitalized Atoms starting with a colon

I’m just wondering if anyone ever has any clever use-cases for atoms named starting with a colon followed by a captial: :Atom. Is there any kind of trending convention around it? I’ve been using it to give a “private” name to a GenServer for sending it debug messages in iex. Is there a better way of doing that? Is there a reason to never use it? This is more of just a fun question—or tedious, depnding on your viewpoint :upside_down_face:

1 Like

Module names in Elixir are atoms starting with capital letters. When you especially want to refer to a module in code, you use module names typically without colons.

I sometimes use them to choose a module implementing the same behavior, for instance in a configuration file.

I would find that convention confusing since I would not be sure if you meant to say Atom (with no :) and therefore a module name, or not.

Part of why I would be unsure of your intent is because:

iex> Atom == :Atom
false

iex> Atom == :"Elixir.Atom"
true
1 Like
@smileytoemoji [ :P: 😛 ]
2 Likes

if you want a “private” atom, surround it by a double underscore.
:__atom__,
that is the convention used in Elixir.

For a real case, check this PR Rename struct attribute in defstruct by eksperimental · Pull Request #10354 · elixir-lang/elixir · GitHub and the issue linked in it,
It is not about atoms but attributes, but I guess it is the same convention.

3 Likes

Structs use the private key named :__struct__ to store the name of the struct.

1 Like