[erlang-questions] maps or records?

Benoit Chesneau bchesneau@REDACTED
Mon Feb 29 13:21:40 CET 2016


Thanks all for the answers it's useful !

On Fri, Feb 26, 2016 at 5:56 PM Garrett Smith <g@REDACTED> wrote:

> On Fri, Feb 26, 2016 at 10:23 AM Benoit Chesneau
>
>
>> So would you se a maps instead of a record when you need to share the
>> returned result with apps that depends on your library? Instead of making
>> that result opaque and provide functions to access it? Which sound
>> ridiculous sometimes, since at the end what you do is a get on a record key
>> ... Curious what others do in that case?
>>
>
> What's the nature of the data? If it's a map of keys to values, I think
> map is a good data type. E.g. I think a database row is well represented as
> a map, as columns/fields tend to differ based on what you're retrieving.
>
> Maybe a good test is the one you mentioned - if you're module is simply
> providing a bunch of pass-throughs to peel off record fields, it wants to
> be a map.
>


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" . The record will likely change. 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.

- benoit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160229/b1b32037/attachment.htm>


More information about the erlang-questions mailing list