[#38647] [Ruby 1.9 - Bug #5130][Open] Thread.pass sticks on OpenBSD — Yui NARUSE <naruse@...>

16 messages 2011/08/01

[#38653] [Ruby 1.9 - Bug #5135][Open] Ruby 1.9.3-preview1 tests fails in Fedora Rawhide — Vit Ondruch <v.ondruch@...>

31 messages 2011/08/01

[#38666] [Ruby 1.9 - Bug #5138][Open] Add nonblocking IO that does not use exceptions for EOF and EWOULDBLOCK — Yehuda Katz <wycats@...>

61 messages 2011/08/01
[#38667] Re: [Ruby 1.9 - Bug #5138][Open] Add nonblocking IO that does not use exceptions for EOF and EWOULDBLOCK — Aaron Patterson <aaron@...> 2011/08/01

On Tue, Aug 02, 2011 at 07:35:15AM +0900, Yehuda Katz wrote:

[#38669] Re: [Ruby 1.9 - Bug #5138][Open] Add nonblocking IO that does not use exceptions for EOF and EWOULDBLOCK — Urabe Shyouhei <shyouhei@...> 2011/08/01

(08/02/2011 07:46 AM), Aaron Patterson wrote:

[#38671] Re: [Ruby 1.9 - Bug #5138][Open] Add nonblocking IO that does not use exceptions for EOF and EWOULDBLOCK — Eric Wong <normalperson@...> 2011/08/01

Urabe Shyouhei <shyouhei@ruby-lang.org> wrote:

[#38695] [Ruby 1.9 - Bug #5144][Open] Remove GPL file from repository — Vit Ondruch <v.ondruch@...>

17 messages 2011/08/02

[#38706] [Ruby 1.9 - Bug #5147][Open] mkmf should not require static library when ruby is built with --enable-shared — Vit Ondruch <v.ondruch@...>

9 messages 2011/08/02

[#38894] Why Ruby has versioned paths? — V咜 Ondruch <v.ondruch@...>

Hello, could somebody please elaborate about reasons why Ruby uses versioned

9 messages 2011/08/10

[#38972] [Ruby 1.9 - Bug #5193][Open] ruby_thread_data_type linker errors fixed with RUBY_EXTERN — Charlie Savage <cfis@...>

28 messages 2011/08/16

[#38980] :symbol.is_a?(String) — Magnus Holm <judofyr@...>

http://viewsourcecode.org/why/redhanded/inspect/SymbolIs_aString.html

8 messages 2011/08/16

[#39025] [Ruby 1.9 - Feature #5206][Open] ruby -K should warn — Eric Hodel <drbrain@...7.net>

14 messages 2011/08/19

[#39062] Releasing r33028 as Ruby 1.9.3 RC1 — Yugui <yugui@...>

Hi,

17 messages 2011/08/23

[#39093] [Ruby 1.9 - Bug #5227][Open] Float#round fails on corner cases — Marc-Andre Lafortune <ruby-core@...>

14 messages 2011/08/24
[#39115] [Ruby 1.9 - Bug #5227][Assigned] Float#round fails on corner cases — Yui NARUSE <naruse@...> 2011/08/26

[#39126] Re: [Ruby 1.9 - Bug #5227][Assigned] Float#round fails on corner cases — Marc-Andre Lafortune <ruby-core-mailing-list@...> 2011/08/26

Hi

[#39120] [Ruby 1.9 - Bug #5233][Open] OpenSSL::SSL::SSLSocket has problems with encodings other than "ascii" — Niklas Baumstark <niklas.baumstark@...>

9 messages 2011/08/26

[#39142] [Ruby 1.9 - Bug #5239][Open] bootstraptest/runner.rb: assert_normal_exit logic broken on Debian/GNU kFreeBSD — Lucas Nussbaum <lucas@...>

11 messages 2011/08/27

[#39162] [Ruby 1.9 - Bug #5244][Open] Continuation causes Bus Error on Debian sparc — Lucas Nussbaum <lucas@...>

29 messages 2011/08/28

[ruby-core:38956] [Ruby 1.9 - Feature #4801] Shorthand Hash Syntax for Strings

From: Tom Wardrop <tom@...>
Date: 2011-08-15 02:54:08 UTC
List: ruby-core #38956
Issue #4801 has been updated by Tom Wardrop.


Sounds like everyone wants to get down to the root causes here, which is great, so I'll jump on the band wagon. As I see it, all these problems stem from the fact that symbols and strings are too conceptually similar, in fact they're the same when you really think about. A symbol IS a string. You could say that Strings ARE string data, where as symbols REPRESENT string data, in the same way that "some string" is the string object, and lvar in (lvar = "some string") represents that string object. The difference is that 'some string' == lvar is true, where as 'some string' == :'some string' is not. Symbols are like variables, except that the data the symbol (variable) references is also the name of the variable, thus in my opinion, 'some string' is equal :'some string'. I see no reason to make such a rigid distinction between strings and symbols.

If I was to define what a symbol is, it would be: A named string, where the name of the string 

In Ruby, the only differences between strings and symbols are their semantic meaning, and how they're handled internally in regards to memory. The fact remains though that they're both strings. This is why people get caught out with Hashes, and why HWIA is so handy. It's not that people don't understand the differences, but it's just that their difference are not significant enough, thus one is prone to interchange the two which is what causes many of those hard to track down bugs. This is especially the case when accessing hases with dynamic keys, such as from a configuration file or some other external data source such as a database or user input.

Thus as I see it, the simplest and most natural solution would be to make strings and symbols equal. They can both remain as different Ruby classes, in fact they're implementations can remain exactly the same, you'd only have to change methods such as #eql? on the String and Symbol classes to fix the majority of String/Symbol related problems (so 'some string' == :'some string'). Though to do it properly and with respect to the principal of least surprise, the Symbol class would have to support all string methods, and symbols would have to be implicitly cast to strings when used in the context of a string - if you didn't do this you'd probably have more problems, e.g.

def say_hello(name)
  "Hello #{name.upcase}"
end
say_hello :John #=> "Hello JOHN"

That result of that example is completely desireable. Can you imagine how stress-free Ruby programming would be if Symbols were treated more like Strings?

Can anyone tell me what the advantage is of making such a rigid distiction between Symbols and Strings? Can anyone think of an example where making 'some string' == :'some string' would cause undesireable behaviour in code, assuming the Symbol class implements all the methods of the String class as well as supporting implicit conversion?
----------------------------------------
Feature #4801: Shorthand Hash Syntax for Strings
http://redmine.ruby-lang.org/issues/4801

Author: Tom Wardrop
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 


Assuming there's no technical limitation or ambiguities, I suggest that the shorthand syntax for symbol's in the context of an array, be applied to strings also.

E.g. {'key': 'value'}

I don't believe there are any syntax ambiguous that this would give rise to. The only consideration that may need to be made, is if there are plans to support shorthand syntax for quoted symbols, e.g. {'key': 'value'}. If quoted symbols are off the table, then there's no harm in implementing a shorthand hash syntax for strings. This may stem the growing problem of what I like to call 'symbolitis' , where symbol's are selected as the key type purely for their aesthetics and ease of use, even when strings are a more appropriate choice.

Thoughts?


-- 
http://redmine.ruby-lang.org

In This Thread