Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Rasmus Lerdorf
On 01/05/2013 03:43 PM, Kris Craig wrote: > Granted, but other use-cases have already been presented as well. > Obviously the one I suggested would no longer be useful if PHP adopts > enums. Actually, I didn't see any other cases. The fact that we have interned immutable strings in PHP invalidate

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Stas Malyshev
Hi! > I'm still a total newb when it comes to Ruby, but as I understand it, a > symbol can be particularly helpful by maximizing code readability > without sacrificing efficiency. As a PHP guy, I tend to think of a Ruby > symbol as a constant that doesn't need to be defined or set. Its value St

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Kris Craig
On Sat, Jan 5, 2013 at 3:39 PM, Rasmus Lerdorf wrote: > On 01/05/2013 03:36 PM, Kris Craig wrote: > > > > > > On Sat, Jan 5, 2013 at 3:32 PM, Rasmus Lerdorf > > wrote: > > > > On 01/05/2013 03:29 PM, Kris Craig wrote: > > > > > In both cases, we really don't ca

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Rasmus Lerdorf
On 01/05/2013 03:36 PM, Kris Craig wrote: > > > On Sat, Jan 5, 2013 at 3:32 PM, Rasmus Lerdorf > wrote: > > On 01/05/2013 03:29 PM, Kris Craig wrote: > > > In both cases, we really don't care what the actual values of > brown, black, > > and purple ar

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Nikita Popov
On Sun, Jan 6, 2013 at 12:29 AM, Kris Craig wrote: > I'm still a total newb when it comes to Ruby, but as I understand it, a > symbol can be particularly helpful by maximizing code readability without > sacrificing efficiency. As a PHP guy, I tend to think of a Ruby symbol as > a constant that d

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Kris Craig
On Sat, Jan 5, 2013 at 3:32 PM, Rasmus Lerdorf wrote: > On 01/05/2013 03:29 PM, Kris Craig wrote: > > > In both cases, we really don't care what the actual values of brown, > black, > > and purple are. We just want it to be unique so we can reference each of > > them in a visually friendly way w

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Rasmus Lerdorf
On 01/05/2013 03:29 PM, Kris Craig wrote: > In both cases, we really don't care what the actual values of brown, black, > and purple are. We just want it to be unique so we can reference each of > them in a visually friendly way with minimal performance impact. That's > where I could see a valid

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Kris Craig
On Sat, Jan 5, 2013 at 2:49 PM, Stas Malyshev wrote: > Hi! > > > I know I shouldn't write "Ruby" in the subject of a letter for > > php-internals ML, but... Just wanted to ask, is anybody interested in > this > > feature in PHP? > > As I understand, :foo is basically an interned string "foo". But

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Stas Malyshev
Hi! > I know I shouldn't write "Ruby" in the subject of a letter for > php-internals ML, but... Just wanted to ask, is anybody interested in this > feature in PHP? As I understand, :foo is basically an interned string "foo". But in PHP all constant strings are interned now, so the only thing

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Никита Нефедов
On Sat, Jan 5, 2013 at 6:58 PM, Nikita Nefedov wrote: ** Though there would be a little speed-up because with Symbols array's Buckets will keep numeric key, so instead of memcmp you will need to just compare two longs when retrieving element. Before memcmping the array keys PHP will fir

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Nikita Popov
On Sat, Jan 5, 2013 at 6:58 PM, Nikita Nefedov wrote: > ** > Though there would be a little speed-up because with Symbols array's > Buckets will keep numeric key, so instead of memcmp you will need to just > compare two longs when retrieving element. > Before memcmping the array keys PHP will fi

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Nikita Nefedov
On Sat, 05 Jan 2013 12:21:26 -, Nikita Popov wrote:On Sat, Jan 5, 2013 at 3:07 PM, Nikita Nefedov wrote: What symbols can give: 1. More convenient way to use it almost everywhere as a replacement for strings and sometimes for constants. There's a lot of code that uses ar

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Tom Boutell
If symbols could use the sign bit or otherwise distinguish from typical integer keys one would have some hope of meaningful debugging output. I don't think it makes sense to mix integer keys and symbol keys but being able to differentiate them for debugging purposes would be great. However since

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Ivan Enderlin @ Hoa
On 05/01/13 13:21, Nikita Popov wrote: [snip] If this is about memory savings, then I don't think it will help at all. PHP uses interned strings, so all those "label" etc strings in your above example actually use the same string value. The hash for those strings is also precomputed, so symbol do

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Nikita Popov
On Sat, Jan 5, 2013 at 3:07 PM, Nikita Nefedov wrote: > What symbols can give: > 1. More convenient way to use it almost everywhere as a replacement for > strings and sometimes for constants. There's a lot of code that uses arrays > as a parameter-stores. For example, here's how you usually defin

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Ivan Enderlin @ Hoa
Hi :-), Nice proposal but I have few questions and remarks. My first question is how to delete symbols? I don't know if it is useful or not. We should discuss about that. Is `unset(:foo)` enough? How are they handled by the GC? Another question is: where are we able to use symbols? Is it all

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Nikita Nefedov
On Sat, 05 Jan 2013 10:27:01 -, Crocodile wrote:Sounds like it could make some sense. However, I've got a question..array(  'label' => 'Comment', 'required' => false,  'property_path' => 'properties.comment') is actually equivalent to array( 'label' => 'Comment',  'property_path' => 'pro

Re: [PHP-DEV] Ruby's symbols

2013-01-05 Thread Crocodile
Sounds like it could make some sense. However, I've got a question.. array( 'label' => 'Comment', 'required' => false, 'property_path' => 'properties.comment' ) is actually equivalent to array( 'label' => 'Comment', 'property_path' => 'properties.comment', 'required' => false, ) (Notice t

[PHP-DEV] Ruby's symbols

2013-01-05 Thread Nikita Nefedov
I know I shouldn't write "Ruby" in the subject of a letter for php-internals ML, but... Just wanted to ask, is anybody interested in this feature in PHP? You can read about it here: http://www.randomhacks.net/articles/2007/01/20/13-ways-of-looking-at-a-ruby-symbol It can be implemented in P