Erlang Naming Conventions - for a simple-one-for-one supervisor whose child is a supervisor?

What is the naming convention for a simple-one-for-one supervisor whose child is a supervisor?

A simple example could be that I have a tcp_session process that is supervised by a tcp_session_sup process. The tcp_session_sup has additional children for assisting with the TCP session. I am going to have multiple TCP sessions that are going to be created dynamically. So, I’d like to create a simple_one_for_one supervisor to spin off TCP sessions. What should I name this supervisor, tcp_session_sup_sup??

Simple_TCP_Example

2 Likes

I don’t think there is a convention, but in the absence of a better name, yes, that is what is done most of the time :woman_shrugging: Erlangers are a pretty pragmatic folk I guess :sweat_smile:

4 Likes

In your particular example you could name the top supervisor tcp_sessions_sup since it supervises multiple sessions as opposed to a single session. It follows that the supervisor for a single session could be named tcp_session_sup as it already is.

When I have similar problems this is usually a symptom of the fact that I have not thoroughly thought out the way in which to decompose the particular problem I’m trying to solve.

3 Likes

When is doubt… just don’t name it. After all, what is the purpose of naming a process?

3 Likes

Is this about naming the module or naming a process? :thinking:

2 Likes

I understood it as naming the module. @joseph?

1 Like

Yes, this is about naming a process. I appreciate the insights. I like the idea of tcp_sessions_sup, and will move down that path. It is also good to know that it won’t be viewed as crazy if a module ends up being named *_sup_sup, but it makes sense to view that as possible a gap in my solution.

2 Likes

You have to be careful if you name a process after the module running as it restricts to having only ONE instance of that process as the name is unique. I know it is common to do it but avoid it as a rule.

In this case who as started the tcp_sessions_sup_sup process?

2 Likes

This makes perfect sense. In my case, I am not naming supervisor processes. Instead, I am using pids for sending messages.

In this case a process running in the tcp_sup module started the process in the tcp_session_sup_sup module.

1 Like

There are two problems with naming processes.
One has been noted: only one process can have a
given name (that’s what it means to be a name).
Another is that naming destroys encapsulation.
If a process is not named, it can only receive
messages from a process to which its PID has been
communicated in a controlled way. If a process
is named, any process can send anything it likes
to its named victim.
One of the projects I did for SERC in Melbourne
was to come up with a scheme for module-local
process names, the -pidname declaration. The idea
was to have something intermediate between no-names
and node-global names. At the time, almost all uses
of process names in the OTP sources could have been
module-local.
Obviously node-global names have their uses, just be
careful with them.

1 Like