News for hackers. Stuff that matters.
Re:Why Ruby Has Symbols by tomc1985 on Thursday April 14, 2022 @01:23PM (#31030120)
The article is an extremely needlessly complicated explanation of a relatively simple principle: symbols are stored once and referenced by pointer, strings are stored multiple times and not so easily compared. Ergo, for many use-cases symbols are faster and use less memory.

Some of these use cases are little tokens like single words that are used in as values in function arguments, or a switch statement. On the other hand, storing the user's inputted name as a symbol whilst copying that data to your model object is probably not a good idea.

Yes this explanation leaves out a lot of detail.

There are no comments on this comment yet.