From: merch-redmine@... Date: 2018-01-08T18:12:30+00:00 Subject: [ruby-core:84733] [Ruby trunk Feature#14336] Create new method String#symbol? and deprecate Symbol class Issue #14336 has been updated by jeremyevans0 (Jeremy Evans). dsferreira (Daniel Ferreira) wrote: > Why did frozen string literals outperformed symbols in ruby 2.3.0 and now that is not the case in 2.5.0? > In fact it seems frozen string literals have regressed! They didn't regress. There is overlap between the ranges, so you can't say with confidence statistically using the benchmark whether symbols or strings is faster, or whether the results have changed between 2.3 and 2.5: ~~~ 2.3: literal fstring 10.969M (�� 3.7%) => 10.56..11.37 symbol 10.809M (�� 5.3%) => 10.24..11.38 2.5: literal fstring 10.701M (�� 3.3%) => 10.35..11.05 symbol 11.121M (�� 3.4%) => 10.74..11.59 ~~~ ---------------------------------------- Feature #14336: Create new method String#symbol? and deprecate Symbol class https://bugs.ruby-lang.org/issues/14336#change-69453 * Author: dsferreira (Daniel Ferreira) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- From the discussions on the three previous issues related to the String vs Symbol subject ([5964](https://bugs.ruby-lang.org/issues/5964), [7792](https://bugs.ruby-lang.org/issues/7792), [14277](https://bugs.ruby-lang.org/issues/14277)) there are some conclusions we can assume: * Current String vs Symbol is not the ideal scenario. See: Matz and Koichi comments. * Current philosophy is to use Symbols as identifiers and Strings when strings are needed. * Current situation is that Symbols are being used in many code bases as strings except for strings that really need the String methods. * Current situation is that we are designing APIs to handle both String and Symbol inputs forcing an overhead of API development. I propose the deprecation of `Symbol` class and the introduction of `String#symbol?`. ```ruby foo = :foo foo.class # => String foo.symbol? # => true bar = "bar" bar.class # => String bar.symbol? # => false ``` For backwards compatibility transition path I propose: ```ruby class Symbol def self.===(var) warn ("Warning message regarding deprecated class") if var.class == Symbol true elsif var.class == String && var.symbol? true else false end end end class String def is_a?(klass) case klass when String true when Symbol self.symbol? else false end end end ``` -- https://bugs.ruby-lang.org/ Unsubscribe: