Hi,
I’ve read Joe Armstrong’s opinion that “records are dead, long live maps,” and I understand the benefits of maps in terms of flexibility and introspection. (https://joearms.github.io/#2014-02-01%20Big%20changes%20to%20Erlang)
However, I’m specifically interested in using maps with predefined keys and types, like this:
type state() :: #{queue := queue:queue(), priority_map := #{...},...}.
When I look at recent Erlang codebases, like WhatsApp’s edb repository, I see both approaches being used:
-
In edb_server.erl, they use a
-record(state, {...})for the gen_server state. https://github.com/WhatsApp/edb/blob/a6bba73305fad82e4e6cfe338786c707435c09ab/edb_core/src/edb_server.erl#L60 -
In edb_gatekeeper.erl, they use a
-type state() :: #{...}with a map for the gen_server state. https://github.com/WhatsApp/edb/blob/a6bba73305fad82e4e6cfe338786c707435c09ab/edb_core/src/edb_gatekeeper.erl#L41
This makes me wonder:
-
is there a community consensus or best practice today regarding when to use records vs maps for gen_server state?
-
Are records still preferred in some contexts (e.g., performance, pattern matching), or is it just legacy code?
-
Is using maps with strict typing (via -type) considered idiomatic now?
Any insights or recommendations would be greatly appreciated!