Use of maps for GenServer state variables

Tangentially related to Handling options in Erlang/OTP APIs - Chat / Discussions - Erlang Forums.

The convention is generally to use locally defined records for state in GenServers (et al.)

Are most developers persisting with this convention, or is there a gradual transitioning from records to maps?

2 Likes

A carefully crafted record (tree) outperforms maps and gives you
compile time checking of the keys, so they are not dead yet…

6 Likes

For state data, I generally prefer records over maps, both in gen_server and gen_statem implementations, mainly for the reason of compile time key checking.

6 Likes

I prefer records as well both in gen_server and gen_statem.

8 Likes

It’s records for me, too :woman_shrugging: State constructs as used in gen_server/gen_statem implementations as I use them do not need the flexibility of maps, instead the rigidity of records is IMO rather a benefit than a limitation there. The only time this gets in the way is when you are doing hot code upgrades that change the record structure, but personally I rarely need to do that.

7 Likes