[erlang-questions] map elements in defined order

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Thu Oct 26 20:31:43 CEST 2017


It is generally a bad idea to rely on order in anything which uses a hash
function. The hash function is often subject to change---rather quickly I
might add if it proves to be a security bug. Picking a family of hashes and
seeding it randomly is usually a good trick.

Our "sister language" Go *randomizes* iteration order on its maps. This is
to force programmers into not relying on the map order at all, even if it
happens to be ordered right now. This opens up implementations in the
future.

If you wanted order in a map, it would be *far* better if you could create
a map based on RB-trees or the like. Those are naturally ordered by
structure. OCaml, for instance, defines Hash Tables as well as Maps. The
latter is the ordered variant.


On Thu, Oct 26, 2017 at 8:07 PM Ulf Wiger <ulf@REDACTED> wrote:

> But they *are* ordered. Otherwise, comparison of two maps would be
> undefined.
>
> BR,
> Ulf W
>
>
> Den 26 okt. 2017 18:20 skrev "Roger Lipscombe" <roger@REDACTED>:
>
> On 26 October 2017 at 16:30, Ulf Wiger <ulf@REDACTED> wrote:
> > Wouldn't it be reasonable to have such a function?
>
> First thought: No, because people would start abusing it. Maps *aren't*
> ordered.
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20171026/5606bc97/attachment.htm>


More information about the erlang-questions mailing list