title: Are there any advantages using maps instead of records to hold state in Erlang processes?
body: <p>Most of the books or online resources I've seen are all using records to hold the state of a process (probably because that was the way for more(?) than a decade). On the other hand, maps are effectively used to replace tuples in stdlib (for example <a href="http://www.erlang.org/doc/man/supervisor.html" rel="nofollow noreferrer">childspecs in the supervisor module</a>). </p>
  
  <p>As an example, I am working my way through <a href="http://learnyousomeerlang.com/finite-state-machines" rel="nofollow noreferrer">Learn You Some Erlang's Finite State Machines</a> chapter and the <code>state</code> record could be replaced with a map, declared in the <code>init/1</code> callback needed by <code>gen_fsm</code>. </p>
  
  <ul>
  <li>The record declaration won't be needed and most of what I've read so far, a best practice is to keep them local anyway as <code>.hrl</code> files make it harder to track errors. </li>
  <li>Referring to the process state in function clauses would also be shorter but they both clearly convey the structure of the state variable and a couple extra characters are not a concern.</li>
  </ul>
  
  <p><strong>Also, would it be more efficient?</strong><br>
  I know that a well-thought out benchmark would answer my question but I am only a couple weeks into learning Erlang and the <a href="https://stackoverflow.com/questions/23106543/illegal-pattern-in-map-of-erlang">maps</a> <a href="http://www.erlang.org/eeps/eep-0043.html" rel="nofollow noreferrer">module</a> is fairly new and still <a href="http://erlang.org/pipermail/erlang-bugs/2014-March/004238.html" rel="nofollow noreferrer">changing</a>.</p>
  
  <p>UPDATE: Thanks to I GIVE TERRIBLE ADVICE, I read the <a href="http://learnyousomeerlang.com/maps" rel="nofollow noreferrer">LYSE chapter on maps</a> more thoroughly and the answer is clear:</p>
  
  <blockquote>
    <p>Using records has the advantage that the keys are known at compile
    time that brings advantages of  </p>
    
    <ul>
    <li>fast access to specific values (faster than what is possible dynamically)</li>
    <li>additional safety (crash early rather than corrupting state)</li>
    <li>easier type checking  </li>
    </ul>
    
    <p><strong>These make records absolutely appropriate for a process' internal state</strong>, despite the occasional burden of writing a more verbose
    code_change function.</p>
    
    <p>On the other hand, where Erlang users would use records to represent
    complex nested key/value data structures (oddly similar to objects in
    object-oriented languages) that would frequently cross module
    boundaries, maps will help a lot. Records were the wrong tool for that
    job.</p>
  </blockquote>