[erlang-questions] maps or records?

Siraaj Khandkar siraaj@REDACTED
Mon Feb 29 16:12:52 CET 2016

On 2/29/16 7:21 AM, Benoit Chesneau wrote:
> I was thinking to this simple example:
> I have a function hackney_url:parse_url() returning a record #hackney_url{}
> . This record can be used internally but also externally by the
> applications that need it. Which requires for now to include
> "hackney_lib.hrl" .

I strongly favor dedicated include files per record, as it is the least 
invasive to the user's namespace. Also fully-qualified (i.e. 
app-name-prefixed) (public) record names, which is what you already did 

> The record will likely change.

This should be addressed by (hopefully semantic) versioning of the app 
and users' considerations of what accessors need updating upon upgrade.

> On the other hands I am
> not sure I like to have to import the include file to get its definition
> (or copy this definition in another file, or just use the tuple) .
> So in that case I wonder if using a maps wouldn't be more appropriate.

Ideally, a language would allow you to reference exported records from 
other modules, but, given what we have so far in Erlang - I don't think 
there's an ideal answer - it's your artistic decision, what you want to 
compromise :)

(as I already mentioned earlier, I still favor records for such cases (a 
product type), despite some of their inconveniences, but I also never do 
runtime code upgrades...)

More information about the erlang-questions mailing list