"The Rails Way" book mentions the following regarding the create_table method: Why do we specify identifiers with symbols instead ofstrings? Both will work, but symbols require one less keystroke. What is meant by: "But symbols require one less keystroke?" Thanks. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 15 July 2010 09:38, Abder-Rahman Ali <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> "The Rails Way" book mentions the following regarding the create_table > method: > > Why do we specify identifiers with symbols instead ofstrings? Both will > work, but symbols require one less keystroke. > > What is meant by: "But symbols require one less keystroke?""string" :string one has two quote marks; the other only one colon. But "less keystrokes" is a glib argument in favour of symbols... a better reason for using symbols over strings is that symbols are more efficient in memory. They act like pointers to a single string, where quoted-strings all exist individually in memory, so if you use the same string a lot, you use lots more memory than if you use the same symbol a lot. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Pavling wrote:> On 15 July 2010 09:38, Abder-Rahman Ali <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> "The Rails Way" book mentions the following regarding the create_table >> method: >> >> Why do we specify identifiers with symbols instead ofstrings? Both will >> work, but symbols require one less keystroke. >> >> What is meant by: "But symbols require one less keystroke?" > > "string" > :string > > one has two quote marks; the other only one colon. > > But "less keystrokes" is a glib argument in favour of symbols... a > better reason for using symbols over strings is that symbols are more > efficient in memory. They act like pointers to a single string, where > quoted-strings all exist individually in memory, so if you use the > same string a lot, you use lots more memory than if you use the same > symbol a lot.Thanks for your reply. Regarding memory usage. If the symbol is acting like a pointer and I use it a lot, doesn''t that mean I''m using the string the symbol is pointing to, and thus using memory? I didn''t really get the memory benefit of symbols over strings if that can be described a bit. Thanks. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 15, 7:24 pm, Abder-Rahman Ali <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Regarding memory usage. If the symbol is acting like a pointer and I use > it a lot, doesn''t that mean I''m using the string the symbol is pointing > to, and thus using memory? I didn''t really get the memory benefit of > symbols over strings if that can be described a bit. >The difference is that a given symbol only exists in memory once whereas you could have many copies of an identical string floating around, each using however many bytes. The flipside is that symbols are never released. See also http://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Jul 15, 7:24�pm, Abder-Rahman Ali <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> Regarding memory usage. If the symbol is acting like a pointer and I use >> it a lot, doesn''t that mean I''m using the string the symbol is pointing >> to, and thus using memory? I didn''t really get the memory benefit of >> symbols over strings if that can be described a bit. >> > > The difference is that a given symbol only exists in memory once > whereas you could have many copies of an identical string floating > around, each using however many bytes. The flipside is that symbols > are never released. See also > http://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings > > FredThanks a lot. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.