[99s-extend] Cowboy: Maps instead of records for context variables

Loïc Hoguin essen at ninenines.eu
Tue Oct 20 15:22:39 CEST 2015


On 10/20/2015 03:19 PM, Ivan Uemlianin wrote:
> Dear All
>
> Would there be any reason against using a map instead of a record for
> the context variable in a Cowboy REST resource?
>
> Quite often I have a few resources doing very similar things in their
> callbacks, and I'd like to abstract out the similarities into a module -
> but I don't want to share a record between modules.
>
> Maps seem to be a good fit, and I can't think of any downside
> (performance hit should be tiny).
>
> Can anyone give me reasons to stick with records?

The only reason to use records is to keep typespecs information to 
improve Dialyzer's error reporting.

Personally I have no problems going with just maps for all kinds of 
states, even if they are in the same module. This is partly because I 
rely a lot more on tests than on Dialyzer to tell me my program is wrong.

Cheers,

-- 
Loïc Hoguin
http://ninenines.eu
Author of The Erlanger Playbook,
A book about software development using Erlang


More information about the Extend mailing list