Issue #14336 has been updated by Hanmac (Hans Mackowiak).


rosenfeld (Rodrigo Rosenfeld Rosas) wrote:
> > it means that the developer doesn't think about his own application enough to know if something would be a String or Symbol, or uses user input without checking which is even worse
> 
> It has nothing to do with the developer but with the library author. They can't know whether the developer would want a symbol or a string as the hash key when deserializing back.
> 
> And this has nothing to do with user input, since the user doesn't talk directly to Redis.

it does: if the application developer doesn't care what he input and output into a third party library he used, then it's his problem
you can't know what the third party does with it, thats what documentation of that third party library is for


for example if i would do something that does return deserialized stuff, i would do parameter to control what kind should be returned
like what if your application wants the third library to return deserialized stuff returned as objects like Struct?
yaml for example support some magic comment for ruby struct, while json does not.
what if the your application or your users what json to return objects and not just Hash?
do your thing support that too?

> 
> > you should always check the documentation of the code you use to check all the corner cases where something would throw an Exception
> 
> Most of the time we spend coding is reading other's code. Most of the time other's code exist directly in the application and there's no documentation for them at all.
You know, from the method name, that it's supposed to return a hash with identifier as keys, but you always have to check just to make sure those identifiers are strings or symbols, or maybe the hash is a HWIA. 

thats where rdoc and yard is for (and in extension ri), you not only has the method name, but also the parameters, what type they should be, and example how to call the function and what it should return

for example the Module#constants or const_get or const_set functions. its explicit said you can use both a symbol or a string as names for const_get and const_set, but constants only would use symbols.

or was you one of them that had a problem with that change after it was done in ruby 1.9?



----------------------------------------
Feature #14336: Create new method String#symbol? and deprecate Symbol class
https://bugs.ruby-lang.org/issues/14336#change-69688

* Author: dsferreira (Daniel Ferreira)
* Status: Rejected
* 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: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>