3 ms·
The difference between symbols and strings only exists at the low level. At the high level they are virtually the same thing.
by TazeTSchnitzel 5y ago
The difference between symbols and strings only exists at the low level. At the high level they are virtually the same thing.
- eternityforest 5y agoIt seems like the difference(As far as I can tell without spending way more time with the article) is deduplication, which other languages already give you with strings. I think thr syntax is slightly nicer than quotes, but it's also more syntax, and there is a limit to how much you can have if you don't want code to look like Perl(Which Ruby is approaching). People are saying it can can be used for some kind of better compile time checking, would be interesting to see that as the main focus?
- klibertp 5y ago> deduplication, which other languages already give you with strings. Aren't Ruby's strings mutable? I'm not sure, but I seem to recall they were/are, in which case you can't really intern them. Python and Java have immutable strings, with the ability to optimize allocations being (probably?) one of the reasons. On the other hand, Symbols in Ruby seem to be immutable, which allows for their interning.
- noneeeed 5y agoIt's optional. By default strings are mutable, but you can freeze them individually, and you can set a directive that makes all string literals as immutable on a file-by-file basis.
- TazeTSchnitzel 5y agoYou can intern strings without preventing mutability using the copy-on-write principle. PHP does it.
- recursive 5y agoIf you copy before you write, you're not mutating, you're making a new thing. e.g. This pseudo code must stand for mutation to be present. a = ... b = a mutate(a) /* b now mirrors a */
- TazeTSchnitzel 5y agoA language runtime can make that work if it wants to. High-level semantics don't need to constrain the implementation.
- deleted 5y ago[deleted]
- jbverschoor 5y agoThey are constants without having to declare them and assign them a globally unique value. Strings are for text (ui/parsing/values)