[erlang-questions] maps or records?

Siraaj Khandkar <>
Fri Feb 26 16:23:16 CET 2016


On 2/26/16 9:50 AM, Benoit Chesneau wrote:
> Hi all,
>
> i tends these days to use maps instead of records, so you dont' have to
> include a file to retrieve the "schema" but I wonder if this is a good idea
> or not. Is there still some usage for records vs maps?

When keys are defined statically (i.e. they do not change at run time), 
such as process state, a tuple (such as an Erlang record) is the 
semantically-correct choice.

When keys are generated dynamically (i.e. they're not (all) known until 
run time), such as a hit rate counter, any dictionary data structure 
(such as an Erlang map, dict, ETS, etc) is the semantically-correct choice.

I realize that not all will agree with prioritizing semantics over 
immediate convenience, but those are my personal values, so take it at 
that :-)

I'm of the opinion that including a file (who's author is hopefully 
conscientious enough to not pollute your namespace) is a small price to 
pay for explicit expression of intention.


More information about the erlang-questions mailing list