[ruby-core:102337] Re: eliminating symbols...
From:
Marc-Andre Lafortune <ruby-core-mailing-list@...>
Date:
2021-01-31 17:21:50 UTC
List:
ruby-core #102337
Agree with @eregon. In my mind there is a big semantic difference between a Symbol and a String. Symbols are identifiers meant for developers and the machine. A program that needs to run in a multi-language environment, all strings should (ideally) be localized, while no symbols will. I probably shouldn't even be arguing on the merits of the idea; the incompatibility alone is reason enough to not change this. On Sun, Jan 31, 2021 at 9:41 AM Benoit Daloze <eregontp@gmail.com> wrote: > I believe Symbols have a significant performance advantages compared to > regular String, i.e., they can always be compared by identity. > However, if a String would know if it's "interned" in the fstring table, > then such optimization could be done for fstring Strings too (if both > operands are fstring Strings). > > IMHO, learning the difference between String and Symbol is part of > learning Ruby. > Symbol are identifiers or enums, String is basically just data. > > On Sun, Jan 31, 2021 at 2:13 AM Eric Wong <normalperson@yhbt.net> wrote: > >> Was just catching up with some of the HashWithIndifferentAccess >> discussion at >> https://bugs.ruby-lang.org/issues/17472 >> >> Could a magic comment (e.g. "# symbols_are_strings: true") >> make :foo a shorthand for a frozen 'foo' String? >> >> If you turn your head sideways, the : character can look like '' >> >> That would provide a migration path which would allow reducing >> the use of Symbols and maybe get rid of it down-the-line(*). >> >> Implementation-wise, every symbol already has a frozen string >> associated with it, so there's no extra memory cost. >> >> >> (*) I now consider Symbols a mistake of the Ruby language design >> and they should've been only an implementation detail. This >> is even more so with GC-able symbols nowadays. But maybe my >> brain is infected by too much Perl5 :P >> >> Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> >> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core> >> > > Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> > <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core> > Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>