aj-foster

aj-foster

Process Dictionary vs. Passing State

tl;dr I have a process that passes around a lot of state. Doing this instead of using the process dictionary affects coding design decisions. What would you do?

I have a project that passes around a lot of state. For example, this tracks the processing of an OpenAPI description as operations and schemas are discovered and named.

So far, I’ve followed the best practice of always passing this state around as arguments rather than using the process dictionary. It makes a few things awkward, like the occasional function that doesn’t need to know or update state except in rare circumstances, but must pass it through anyway. Because this project is meant to be pluggable for its consumers, I’ve made certain choices to avoid passing state in and out of callbacks in situations where a consumer is likely to mismanage the data. This has secondary effects for the project’s architecture which, although workable, reduce flexibility.

As the author, I can foresee and enforce that all of the processing will occur in a single process. I can also provide a suite of safe state management functions that discourage any manual editing of the data. The flexibility of always having the state available to read and write is alluring.

What would you do? Why? If you’re on the side of never use the Process Dictionary, can you imagine a circumstance where you would?

Most Liked

al2o3cr

al2o3cr

An “intermediate” storage strategy might fit better: keep an ETS table (or several) that are passed into functions.

That would give the same “implicit write everywhere” mutability as the process dictionary, without the exactly-one-per-process limitation.

derek-zhou

derek-zhou

Then shouldn’t you just use a GenServer and hide the state from the outside?

Where Next?

Popular in Discussions Top

matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New
Donovan
Hello everyone, I’m so glad to have discovered this awesome community. Thanks for creating it! This is my second post, and apologies for...
New
Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New
Ankhers
Just a little information upfront. Generally speaking, if I feel like I need to either break a pipe chain or use an anonymous function in...
New
nunobernardes99
Hi there Elixir friends :vulcan_salute: In a recent task I was on, I needed to check in two dates which of them is the maximum and which...
New
PragTob
Hey everyone, this has been brewing in my head some time and it came up again while reading Adopting Elixir. GenServers, supervisors et...
New
sergio
There’s a new TIOBE index report that came out that shows Elixir is still not in the top 50 used languages. It also goes on to call Elix...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54120 245
New
axelson
Decided against including more info in the title, but the gist is that Plataformatec sponsored projects will continue with the assets bei...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43487 311
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement