From: daz Date: 2005-11-09T23:57:15+09:00 Subject: Re: Question about symbols Matthew Smillie wrote: > > Thanks for the replies, and if there are no objections to indulging > me a little further... > > > On Nov 9, 2005, at 10:37, daz wrote: > > > > I'll wave my hands (in a completely non-scientific way) at 300..500 > > max. > > (Table look-up isn't hot.) > > Is it really that low? I thought that since symbols are generated > for every name in Ruby (aren't they?), the ceiling would be a little > higher before they started being problematic. > I'm saying that a typical advantage to using :symbols is in code that creates them using the literal syntax (:name) in contrast to 'name'.to_sym (formerly 'name'.intern) e.g.: cust = {:name => 'Acme', :location => 'some locn', :phone => 'nn-nnn', :joindate => Date.new('yy-mm-dd')} cust[:lastupdate] = Date.new('today') if custname == cust[:name] if cust[:lastupdate] > ... custlist[:lastupdate] << cust[:name] end i.e. repeating use of keys/tags within code; same key name into multiple hashes/structs etc. I believe that typing :name in a script is the only way to create a symbol without it having been a ruby String, first. Once you've typed 300 unique :symbols, you've probably reached 6000+ lines of code (?) I don't see any advantage to having nK unique :symbols over nK unique 'strings'. (That doesn't imply there isn't one. :) daz /* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */ /* static char sccsid[] = "@(#) st.c 5.1 89/12/14 Crucible"; */ [...]