3 ms·
I don't think I really grok :symbols, which is also the main thing that puts me off ruby. What's the point? What are they useful for?
by jsmeaton 9y ago
I don't think I really grok :symbols, which is also the main thing that puts me off ruby. What's the point? What are they useful for?
- di4na 9y agogiving a name to things without going into the full complex structure of a string. Think like error code or Enumeration, but with a name that makes sense.
- jetti 9y agoExcept you have to be careful with symbols in Elixir. They don't get cleaned up until a crash. That means in things like Phoenix you aren't supposed to use symbols as parameter maps in your controllers as a user could easily blow up your memory by making tons o' calls. EDIT: I would also add that they are the preferred key for Maps when using internal Map structures (ones that you have complete control over and users don't)
- napsterbr 9y agoThat's a "problem" with the erlang vm actually, you have a limit number of allowed atoms (I think 2 million). When receiving user input, you should not let users create arbitrary atoms because this would allow a atom exhaustion attack. In these cases, what we do is assing a "string" map, something like :input["arbitrary_key"] ETA: default is 1 million atoms actually. It can be increased but it's usually a smell/something to be investigated.
- jetti 9y agoGood point that this isn't Elixir specific but any language that runs on the BEAM.