4 ms·
Oh no same crap of mixing hash symbol and string keys as in ruby? You didnt have to borrow that Elixir! Does Elixir also have HashWithIndifferentAccess?
by joelbluminator 6y ago
Oh no same crap of mixing hash symbol and string keys as in ruby? You didnt have to borrow that Elixir! Does Elixir also have HashWithIndifferentAccess?
- ironmagma 6y agoHonest question, why is this a problem?
- joelbluminator 6y agoJust google HashWithIndifferentAccess...
- e_proxus 6y agoI get a feeling that it is just a band aid because of unsanitized data and sloppy coding practices. If you subscribe to the philosophy of sanitizing and validating user data on the edge as soon as you receive it and then stick to using whatever data type you decided on, this is much less of a problem (any mismatch in runtime would then be considered a bug).
- praveenperera 6y agoElixir does not have HashWithIndifferentAccess
- bglusman 6y agoNot built in, and not remotely suggesting anyone use this, but as an experiment I did build this a few years ago as a toy/to play with a few ways it might look if we ever wanted something similar.... https://hex.pm/packages/indifferent_access https://hex.pm/packages/indifferent_access https://github.com/bglusman/indifferent_access https://github.com/bglusman/indifferent_access (see also https://github.com/vic/indifferent https://github.com/vic/indifferent )
- regulation_d 6y agoTypically string key maps should exist only at the edges of your system, but they are still often necessary when you're interacting with the outside world. Params in Phoenix come in as a string key map because the atom table does not get garbage collected, so where you don't know what keys may be passed in, string keys are necessary to avoid the risk of running OOM. That said, once I know the shape of the data I'm dealing with, I pretty much always convert to an atom key map as quickly as possible. If I see a string key outside of the context of a controller or worker, I am immediately suspicious.
- ch4s3 6y agoYou really should never mix them, String keys are basically only there for accepting untrusted input, and should get sanitized. Any internal map should only have atom keys. String keyed maps exist so that you can accept inputs from untrusted sources without worrying about a malicious or malformed input from overflowing the atom table and crashing your VM.
- bostonvaulter2 6y agoWell you can use any datatype you want as a key in a map. It wouldn't make sense to not allow either atoms or strings.