Hacker News new | ask | show | jobs
by TazeTSchnitzel 1534 days ago
The difference between symbols and strings only exists at the low level. At the high level they are virtually the same thing.
2 comments

It 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?

> 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.

It'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.
You can intern strings without preventing mutability using the copy-on-write principle. PHP does it.
If 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 */
A language runtime can make that work if it wants to. High-level semantics don't need to constrain the implementation.
They are constants without having to declare them and assign them a globally unique value. Strings are for text (ui/parsing/values)