<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Ruby symbols</title>
	<atom:link href="http://www.khelll.com/blog/ruby/ruby-symbols/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.khelll.com/blog/ruby/ruby-symbols/</link>
	<description>What web development means....</description>
	<lastBuildDate>Wed, 10 Mar 2010 20:43:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Twitter</title>
		<link>http://www.khelll.com/blog/ruby/ruby-symbols/comment-page-1/#comment-2198</link>
		<dc:creator>Twitter</dc:creator>
		<pubDate>Wed, 03 Jun 2009 21:02:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=241#comment-2198</guid>
		<description>This is my third time here, just thought I would mention that you are doing a great job</description>
		<content:encoded><![CDATA[<p>This is my third time here, just thought I would mention that you are doing a great job</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Mayer</title>
		<link>http://www.khelll.com/blog/ruby/ruby-symbols/comment-page-1/#comment-137</link>
		<dc:creator>Dan Mayer</dc:creator>
		<pubDate>Thu, 08 Jan 2009 01:26:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=241#comment-137</guid>
		<description>Good post I never really knew why people were pushing to use symbols over strings all the time. The best explanation before this I had heard was that Symbols where &#039;lighter weight&#039; strings. I have used them all the time with out really fully getting it.</description>
		<content:encoded><![CDATA[<p>Good post I never really knew why people were pushing to use symbols over strings all the time. The best explanation before this I had heard was that Symbols where &#8216;lighter weight&#8217; strings. I have used them all the time with out really fully getting it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jack</title>
		<link>http://www.khelll.com/blog/ruby/ruby-symbols/comment-page-1/#comment-136</link>
		<dc:creator>Jack</dc:creator>
		<pubDate>Thu, 08 Jan 2009 00:40:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=241#comment-136</guid>
		<description>My fave use for symbols in Ruby, actually, is for uses roughly equivalent to use cases for &quot;enum&quot; in C: when passing mnemonic codes around between different scopes (something beyond simple &quot;true&quot; and &quot;false&quot;). Practically that&#039;s likely to be similar to metaprogramming but a bit simpler. For example, you might have:

&lt;code&gt;
def submit_button(caption, type=:input)
  # Code for :input, :button, :image, :a_with_onclick or whatever
end
&lt;/code&gt;

...or there&#039;s the slightly more familiar approach of the options hash:

&lt;code&gt;
def add_column(name, type, default_value=nil, options={})
  # code which checks for options[:not_null], options[:key], options[:constraint],
  # options[:comment] et cetera.
end
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>My fave use for symbols in Ruby, actually, is for uses roughly equivalent to use cases for &#8220;enum&#8221; in C: when passing mnemonic codes around between different scopes (something beyond simple &#8220;true&#8221; and &#8220;false&#8221;). Practically that&#8217;s likely to be similar to metaprogramming but a bit simpler. For example, you might have:</p>
<p><code><br />
def submit_button(caption, type=:input)<br />
  # Code for :input, :button, :image, :a_with_onclick or whatever<br />
end<br />
</code></p>
<p>&#8230;or there&#8217;s the slightly more familiar approach of the options hash:</p>
<p><code><br />
def add_column(name, type, default_value=nil, options={})<br />
  # code which checks for options[:not_null], options[:key], options[:constraint],<br />
  # options[:comment] et cetera.<br />
end<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Apostlion</title>
		<link>http://www.khelll.com/blog/ruby/ruby-symbols/comment-page-1/#comment-135</link>
		<dc:creator>Apostlion</dc:creator>
		<pubDate>Thu, 08 Jan 2009 00:28:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=241#comment-135</guid>
		<description>A symbol is not a memory leak. A symbol is a memory saver.

What&#039;s GC, really?

Say, you create a hash as in Glu.ttono.us article listed above, {&quot;abubu&quot; =&gt; &quot;ububa&quot;}, and create another hash, oddly enough, also {&quot;abubu&quot; =&gt; &quot;ububa&quot;}. Well, four strings created, and if you delete the first hash, GC will kill two strings for ya.

If using symbols, you don&#039;t have those &lt;strong&gt;extra&lt;/strong&gt; strings to delete anyway.

And no matter how long your program runs, or whatever fancy loops and hoops it does, if you&#039;re not dynamically creating symbols via #to_sym, only those specific, unique symbols you&#039;ve explicitly named in your code will live. 1Mb memory leak is around 260k such symbols can you even imagine that many symbol names?

As Khaled said, you&#039;re ok unless you start dynamically creating thousands of symbols somewhere.</description>
		<content:encoded><![CDATA[<p>A symbol is not a memory leak. A symbol is a memory saver.</p>
<p>What&#8217;s GC, really?</p>
<p>Say, you create a hash as in Glu.ttono.us article listed above, {&#8220;abubu&#8221; =&gt; &#8220;ububa&#8221;}, and create another hash, oddly enough, also {&#8220;abubu&#8221; =&gt; &#8220;ububa&#8221;}. Well, four strings created, and if you delete the first hash, GC will kill two strings for ya.</p>
<p>If using symbols, you don&#8217;t have those <strong>extra</strong> strings to delete anyway.</p>
<p>And no matter how long your program runs, or whatever fancy loops and hoops it does, if you&#8217;re not dynamically creating symbols via #to_sym, only those specific, unique symbols you&#8217;ve explicitly named in your code will live. 1Mb memory leak is around 260k such symbols can you even imagine that many symbol names?</p>
<p>As Khaled said, you&#8217;re ok unless you start dynamically creating thousands of symbols somewhere.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: khelll</title>
		<link>http://www.khelll.com/blog/ruby/ruby-symbols/comment-page-1/#comment-133</link>
		<dc:creator>khelll</dc:creator>
		<pubDate>Wed, 07 Jan 2009 21:17:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=241#comment-133</guid>
		<description>For guys who are objecting on memory benefits, please have a look at &lt;a href=&quot;http://glu.ttono.us/articles/2005/08/19/understanding-ruby-symbols&quot; rel=&quot;nofollow&quot;&gt;this&lt;/a&gt; article</description>
		<content:encoded><![CDATA[<p>For guys who are objecting on memory benefits, please have a look at <a href="http://glu.ttono.us/articles/2005/08/19/understanding-ruby-symbols" rel="nofollow">this</a> article</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: khelll</title>
		<link>http://www.khelll.com/blog/ruby/ruby-symbols/comment-page-1/#comment-132</link>
		<dc:creator>khelll</dc:creator>
		<pubDate>Wed, 07 Jan 2009 21:06:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=241#comment-132</guid>
		<description>@ Glenn Gillen, you are totally true, that&#039;s why i said:

&lt;blockquote&gt;So use symbols as much as you can, and avoid using stings as much as you can, but take extra care of defining thousands of symbols, cause as mentioned: symbols don&#039;t get deleted till program exits, and thus they stick in memory.&lt;/blockquote&gt;

</description>
		<content:encoded><![CDATA[<p>@ Glenn Gillen, you are totally true, that&#8217;s why i said:</p>
<blockquote><p>So use symbols as much as you can, and avoid using stings as much as you can, but take extra care of defining thousands of symbols, cause as mentioned: symbols don&#8217;t get deleted till program exits, and thus they stick in memory.</p></blockquote>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glenn Gillen</title>
		<link>http://www.khelll.com/blog/ruby/ruby-symbols/comment-page-1/#comment-131</link>
		<dc:creator>Glenn Gillen</dc:creator>
		<pubDate>Wed, 07 Jan 2009 17:52:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=241#comment-131</guid>
		<description>&lt;blockquote&gt;The GC would not have to clean this :Khaled alhabache symbol, cause symbols don&#039;t get deleted till program exits.&lt;/blockquote&gt;

How is that considered considered a more efficient use of memory? The same result as interpreted from others has been:

&lt;blockquote&gt;Let&#039;s start off with memory. Every symbol is a memory leak. I don&#039;t know who said that first, but it&#039;s a great way to think about symbols. Every symbol lives forever&lt;/blockquote&gt;
from &lt;a href=&quot;http://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings&quot; rel=&quot;nofollow&quot;&gt;Josh Susser&lt;/a&gt;

&lt;blockquote&gt;A Ruby symbol is a memory leak. Because of the way Ruby symbols are stored, they can never be garbage collected. So if we create 10,000 one-off symbols that will never use again, will never get the memory back.&lt;/blockquote&gt;
from &lt;a href=&quot;http://www.randomhacks.net/articles/2007/01/20/13-ways-of-looking-at-a-ruby-symbol#11&quot; rel=&quot;nofollow&quot;&gt;Eric Kidd&lt;/a&gt;

I&#039;m sure there are scenarios where this might well be the case, but they&#039;d need to be carefully thought out and measured with real world performance. I would think in the vast majority of cases that leaving these objects sitting around stale in memory is less than optimal.</description>
		<content:encoded><![CDATA[<blockquote><p>The GC would not have to clean this :Khaled alhabache symbol, cause symbols don&#8217;t get deleted till program exits.</p></blockquote>
<p>How is that considered considered a more efficient use of memory? The same result as interpreted from others has been:</p>
<blockquote><p>Let&#8217;s start off with memory. Every symbol is a memory leak. I don&#8217;t know who said that first, but it&#8217;s a great way to think about symbols. Every symbol lives forever</p></blockquote>
<p>from <a href="http://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings" rel="nofollow">Josh Susser</a></p>
<blockquote><p>A Ruby symbol is a memory leak. Because of the way Ruby symbols are stored, they can never be garbage collected. So if we create 10,000 one-off symbols that will never use again, will never get the memory back.</p></blockquote>
<p>from <a href="http://www.randomhacks.net/articles/2007/01/20/13-ways-of-looking-at-a-ruby-symbol#11" rel="nofollow">Eric Kidd</a></p>
<p>I&#8217;m sure there are scenarios where this might well be the case, but they&#8217;d need to be carefully thought out and measured with real world performance. I would think in the vast majority of cases that leaving these objects sitting around stale in memory is less than optimal.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: khelll</title>
		<link>http://www.khelll.com/blog/ruby/ruby-symbols/comment-page-1/#comment-128</link>
		<dc:creator>khelll</dc:creator>
		<pubDate>Wed, 07 Jan 2009 12:00:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=241#comment-128</guid>
		<description>@ nico, true, that won&#039;t work, thanks for mentioning it.</description>
		<content:encoded><![CDATA[<p>@ nico, true, that won&#8217;t work, thanks for mentioning it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nico</title>
		<link>http://www.khelll.com/blog/ruby/ruby-symbols/comment-page-1/#comment-127</link>
		<dc:creator>nico</dc:creator>
		<pubDate>Wed, 07 Jan 2009 10:39:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=241#comment-127</guid>
		<description>In ruby 1.9 :ds.to_i gives a NoMethodError</description>
		<content:encoded><![CDATA[<p>In ruby 1.9 :ds.to_i gives a NoMethodError</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: khelll</title>
		<link>http://www.khelll.com/blog/ruby/ruby-symbols/comment-page-1/#comment-125</link>
		<dc:creator>khelll</dc:creator>
		<pubDate>Wed, 07 Jan 2009 05:43:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.khelll.com/blog/?p=241#comment-125</guid>
		<description>@ John, if you had a look at the &lt;a href=&quot;http://www.ruby-doc.org/core/classes/Object.html#M000333&quot; rel=&quot;nofollow&quot;&gt;Object&lt;/a&gt; API documentation, you will notice that the &#039;send&#039; method receives a symbol, not a string, but ruby casts it for you.
So technically it&#039;s not required, but why to reserve an extra memory to &#039;send&#039;  a string, while you can use a symbol directly.
Then it&#039;s all about efficiency.... </description>
		<content:encoded><![CDATA[<p>@ John, if you had a look at the <a href="http://www.ruby-doc.org/core/classes/Object.html#M000333" rel="nofollow">Object</a> API documentation, you will notice that the &#8217;send&#8217; method receives a symbol, not a string, but ruby casts it for you.<br />
So technically it&#8217;s not required, but why to reserve an extra memory to &#8217;send&#8217;  a string, while you can use a symbol directly.<br />
Then it&#8217;s all about efficiency&#8230;.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
