[erlang-questions] maps or records?

ok@REDACTED ok@REDACTED
Mon Feb 29 23:49:58 CET 2016


>> The record will likely change.

And this is the important clue.

This being the case,

(a) the module must be so written that clients
    don't care what the data structure is.  Treat
    it as an opaque type.  Make sure all access
    to the data is via functions exported from
    the module.

(b) Now the question is what will make it easiest
    to move from one version of your design to another.
    Maps answer the question "how can we make it so that
    existing code isn't broken by ADDING new fields,
    only by renaming or deleting old ones, and reduce
    the breakage from changes to fields that aren't
    mentioned often."  Records answer the question "how
    can we notice breakage really quickly".

    Maps are less ugly than records, but I think records
    are still probably your best bet here.

    Using the access functions listed under (a) inside
    your module will also help to make change easier.





More information about the erlang-questions mailing list