# Create\_table

**URL:** <https://www.ruby-forum.com/t/create-table/191613>\
**Category:** Rails\
**Created:** [July 15, 2010, 10:38am UTC](https://www.ruby-forum.com/t/create-table/191613 "2010-07-15T10:38:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 15, 2010, 10:38am UTC](https://www.ruby-forum.com/t/create-table/191613/1 "2010-07-15T10:38:46Z")

</div>

“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.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 15, 2010, 11:07am UTC](https://www.ruby-forum.com/t/create-table/191613/2 "2010-07-15T11:07:13Z")

</div>

On 15 July 2010 09:38, Abder-Rahman A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 15, 2010, 8:24pm UTC](https://www.ruby-forum.com/t/create-table/191613/3 "2010-07-15T20:24:00Z")

</div>

Michael P. wrote:

> On 15 July 2010 09:38, Abder-Rahman A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 15, 2010, 8:30pm UTC](https://www.ruby-forum.com/t/create-table/191613/4 "2010-07-15T20:30:30Z")

</div>

On Jul 15, 7:24 pm, Abder-Rahman A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings)

Fred

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [July 17, 2010, 6:47pm UTC](https://www.ruby-forum.com/t/create-table/191613/5 "2010-07-17T18:47:05Z")

</div>

Frederick C. wrote:

> On Jul 15, 7:24ï¿½pm, Abder-Rahman A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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  
> [has\_many :through - Symbols are not pretty strings](http://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings)
> 
> Fred

Thanks a lot.
