<?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: RPCFN: Fair Distribution (#6)</title>
	<atom:link href="http://rubylearning.com/blog/2010/01/26/rpcfn-fair-distribution-6/feed/" rel="self" type="application/rss+xml" />
	<link>http://rubylearning.com/blog/2010/01/26/rpcfn-fair-distribution-6/</link>
	<description>Helping Ruby Programmers become Awesome</description>
	<lastBuildDate>Wed, 08 Feb 2012 15:25:03 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Rubyists and Companies I am thankful for in 2010</title>
		<link>http://rubylearning.com/blog/2010/01/26/rpcfn-fair-distribution-6/comment-page-1/#comment-129301</link>
		<dc:creator>Rubyists and Companies I am thankful for in 2010</dc:creator>
		<pubDate>Sat, 18 Dec 2010 03:55:10 +0000</pubDate>
		<guid isPermaLink="false">http://rubylearning.com/blog/?p=3549#comment-129301</guid>
		<description>[...] Edward Gray II, James M. Schorr, Jamie van Dyke, Jeff Langr, Jeff Savin, Jeff Schoolcraft, John Trupiano, Joseph Wilk, Julio Javier Cicchelli, Karmen Blake, Kate Cunningham, Kunal Dua, Lucas Carlson, [...]</description>
		<content:encoded><![CDATA[<p>[...] Edward Gray II, James M. Schorr, Jamie van Dyke, Jeff Langr, Jeff Savin, Jeff Schoolcraft, John Trupiano, Joseph Wilk, Julio Javier Cicchelli, Karmen Blake, Kate Cunningham, Kunal Dua, Lucas Carlson, [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cary Swoveland</title>
		<link>http://rubylearning.com/blog/2010/01/26/rpcfn-fair-distribution-6/comment-page-1/#comment-123060</link>
		<dc:creator>Cary Swoveland</dc:creator>
		<pubDate>Wed, 10 Mar 2010 18:30:07 +0000</pubDate>
		<guid isPermaLink="false">http://rubylearning.com/blog/?p=3549#comment-123060</guid>
		<description>Jacob, thank you for answering my questions about method receivers and the use of &quot;self&quot;, and references to instance variables.  With regard to the latter, I had thought &quot;attr_reader&quot; merely provided a getter for use outside the class definition (since the variable, preceded with &quot;@&quot;, is available within the class directly), but have since recognized the getter can be used within the class as well (and, as you point out, that may be preferred).  I&#039;ll have a look at Dave Thomas&#039; screencast series.  I&#039;m finding two books very helpful: Peter Cooper&#039;s &quot;Beginning Ruby&quot; and the &quot;Ruby Cookbook&quot;.  Getting there...</description>
		<content:encoded><![CDATA[<p>Jacob, thank you for answering my questions about method receivers and the use of &#8220;self&#8221;, and references to instance variables.  With regard to the latter, I had thought &#8220;attr_reader&#8221; merely provided a getter for use outside the class definition (since the variable, preceded with &#8220;@&#8221;, is available within the class directly), but have since recognized the getter can be used within the class as well (and, as you point out, that may be preferred).  I&#8217;ll have a look at Dave Thomas&#8217; screencast series.  I&#8217;m finding two books very helpful: Peter Cooper&#8217;s &#8220;Beginning Ruby&#8221; and the &#8220;Ruby Cookbook&#8221;.  Getting there&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob Hodes</title>
		<link>http://rubylearning.com/blog/2010/01/26/rpcfn-fair-distribution-6/comment-page-1/#comment-123007</link>
		<dc:creator>Jacob Hodes</dc:creator>
		<pubDate>Wed, 10 Mar 2010 04:32:19 +0000</pubDate>
		<guid isPermaLink="false">http://rubylearning.com/blog/?p=3549#comment-123007</guid>
		<description>Hi Cary, sorry so long in reply, and thanks for your comments.

Yes, in most cases, self is the implicit receiver of a method call. I hesitate to say all cases, because I&#039;m quite a newbie myself.

(Rubyists tend to use that word, &quot;receiver,&quot; which reflects the language&#039;s Smalltalk influence, and its idea of &quot;sending messages&quot; rather than &quot;invoking methods&quot;. This threw me off for quite awhile.)

In general, it seems idiomatic Ruby prefers to have the receiver be implicit if it&#039;s self. Private methods can&#039;t have any explicit receiver, including an explicit self, so it makes a difference there. And when defining methods, adding self makes a big difference. Within MyClass, &quot;def my_method&quot; would define an instance method, while &quot;def self.my_method&quot; would define a class method.

The most helpful resource I&#039;ve found on this stuff, covering all the fundamentals of Ruby&#039;s object model, is Dave Thomas&#039;s screencast series: http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming . Yehudah Katz&#039;s blog posts are great, too.

Re: line 100, yes, I could have used the instance variables @values and @num_buckets, and in most intros to OOP I think that would be the recommended approach. But I chose to follow Jay Fields&#039;s advice (link is in the code comments) to not make direct use of instance variables throughout a class&#039;s methods. Rather, I&#039;m wrapping these instance variables in getter methods. The getter is written out as a method in the case of @average_bucket_sum. For @values and @num_buckets, I&#039;m using the shorthand declaration attr_reader :values, :num_buckets to get my getter methods on the cheap.

I didn&#039;t give much thought to the issue of whether the two objectives might not be equivalent. I chose to go with the smallest variance option, as that seemed to reflect the spirit of &quot;fair&quot; distribution. The machines can go slightly longer as a whole, in the interests of solidarity. :)

I like the idea you pose at the end. I&#039;ll give it a shot when I have some time.</description>
		<content:encoded><![CDATA[<p>Hi Cary, sorry so long in reply, and thanks for your comments.</p>
<p>Yes, in most cases, self is the implicit receiver of a method call. I hesitate to say all cases, because I&#8217;m quite a newbie myself.</p>
<p>(Rubyists tend to use that word, &#8220;receiver,&#8221; which reflects the language&#8217;s Smalltalk influence, and its idea of &#8220;sending messages&#8221; rather than &#8220;invoking methods&#8221;. This threw me off for quite awhile.)</p>
<p>In general, it seems idiomatic Ruby prefers to have the receiver be implicit if it&#8217;s self. Private methods can&#8217;t have any explicit receiver, including an explicit self, so it makes a difference there. And when defining methods, adding self makes a big difference. Within MyClass, &#8220;def my_method&#8221; would define an instance method, while &#8220;def self.my_method&#8221; would define a class method.</p>
<p>The most helpful resource I&#8217;ve found on this stuff, covering all the fundamentals of Ruby&#8217;s object model, is Dave Thomas&#8217;s screencast series: <a href="http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming" rel="nofollow">http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming</a> . Yehudah Katz&#8217;s blog posts are great, too.</p>
<p>Re: line 100, yes, I could have used the instance variables @values and @num_buckets, and in most intros to OOP I think that would be the recommended approach. But I chose to follow Jay Fields&#8217;s advice (link is in the code comments) to not make direct use of instance variables throughout a class&#8217;s methods. Rather, I&#8217;m wrapping these instance variables in getter methods. The getter is written out as a method in the case of @average_bucket_sum. For @values and @num_buckets, I&#8217;m using the shorthand declaration attr_reader :values, :num_buckets to get my getter methods on the cheap.</p>
<p>I didn&#8217;t give much thought to the issue of whether the two objectives might not be equivalent. I chose to go with the smallest variance option, as that seemed to reflect the spirit of &#8220;fair&#8221; distribution. The machines can go slightly longer as a whole, in the interests of solidarity. <img src='http://rubylearning.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I like the idea you pose at the end. I&#8217;ll give it a shot when I have some time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RPCFN: Broadsides (#7)</title>
		<link>http://rubylearning.com/blog/2010/01/26/rpcfn-fair-distribution-6/comment-page-1/#comment-122672</link>
		<dc:creator>RPCFN: Broadsides (#7)</dc:creator>
		<pubDate>Mon, 01 Mar 2010 02:16:15 +0000</pubDate>
		<guid isPermaLink="false">http://rubylearning.com/blog/?p=3549#comment-122672</guid>
		<description>[...] RPCFN: Fair Distribution (#6) by John Trupiano. [...]</description>
		<content:encoded><![CDATA[<p>[...] RPCFN: Fair Distribution (#6) by John Trupiano. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cary Swoveland</title>
		<link>http://rubylearning.com/blog/2010/01/26/rpcfn-fair-distribution-6/comment-page-1/#comment-122618</link>
		<dc:creator>Cary Swoveland</dc:creator>
		<pubDate>Fri, 26 Feb 2010 23:50:28 +0000</pubDate>
		<guid isPermaLink="false">http://rubylearning.com/blog/?p=3549#comment-122618</guid>
		<description>Jacob,

As someone new to both Ruby and OOP, I found your program interesting and instructive.  I have a few questions.  I was surprised to see &quot;clone&quot; (line 23) and &quot;map&quot; (37) with no arguments.  I made what I thought was a reasonable assumption: if a method&#039;s object is not specified, it is to be &quot;self&quot;.  Sure enough, when I replaced &quot;clone&quot; with &quot;self.clone&quot; and &quot;map&quot; with &quot;self.map&quot;, your program ran no differently.  Then I shortened &quot;self.each&quot; to &quot;each&quot; in line 46, and again, it made no difference.  Am I correct that &quot;self&quot; is assumed when a method&#039;s object is not specified, and if so, when, if ever, is it considered good practice to include &quot;self.&quot; before the method?

Secondly, I do not understand why you do not need &quot;@values&quot; (as in line 72), rather than &quot;values&quot; (and @num_buckets rather than &quot;num_buckets&quot;), in line 100.  I thought &quot;values&quot; would be regarded as a local variable to average_bucket_sum (and there is no method, &quot;values&quot;). I tried it both ways, but the inclusion of &quot;@&quot; made on difference.  

Though not a Ruby question, I was wondering why you chose an objective different than the one given in the challenge.  Considering that you enumerated all solutions, it would have been just as easy to find the one with the smallest maximum machine time (and, if there were a tie, find the one among them with the smallest variance).

By constructing the set of all solutions, then finding the best among them, as you have done, you would quickly run out of memory for larger problems (that have M^J/M! combinations, for M machines and J jobs).  Here&#039;s a challenge (perhaps an NP-complete one): is there a way to loop through all the possible combinations without constructing all of them first (and without repeating permutations, e.g., if you&#039;ve examined [[2,1], [4,3]] you would not examine [[4,3], [2,1]],  [[2,1], [3,4]] and so on)?.</description>
		<content:encoded><![CDATA[<p>Jacob,</p>
<p>As someone new to both Ruby and OOP, I found your program interesting and instructive.  I have a few questions.  I was surprised to see &#8220;clone&#8221; (line 23) and &#8220;map&#8221; (37) with no arguments.  I made what I thought was a reasonable assumption: if a method&#8217;s object is not specified, it is to be &#8220;self&#8221;.  Sure enough, when I replaced &#8220;clone&#8221; with &#8220;self.clone&#8221; and &#8220;map&#8221; with &#8220;self.map&#8221;, your program ran no differently.  Then I shortened &#8220;self.each&#8221; to &#8220;each&#8221; in line 46, and again, it made no difference.  Am I correct that &#8220;self&#8221; is assumed when a method&#8217;s object is not specified, and if so, when, if ever, is it considered good practice to include &#8220;self.&#8221; before the method?</p>
<p>Secondly, I do not understand why you do not need &#8220;@values&#8221; (as in line 72), rather than &#8220;values&#8221; (and @num_buckets rather than &#8220;num_buckets&#8221;), in line 100.  I thought &#8220;values&#8221; would be regarded as a local variable to average_bucket_sum (and there is no method, &#8220;values&#8221;). I tried it both ways, but the inclusion of &#8220;@&#8221; made on difference.  </p>
<p>Though not a Ruby question, I was wondering why you chose an objective different than the one given in the challenge.  Considering that you enumerated all solutions, it would have been just as easy to find the one with the smallest maximum machine time (and, if there were a tie, find the one among them with the smallest variance).</p>
<p>By constructing the set of all solutions, then finding the best among them, as you have done, you would quickly run out of memory for larger problems (that have M^J/M! combinations, for M machines and J jobs).  Here&#8217;s a challenge (perhaps an NP-complete one): is there a way to loop through all the possible combinations without constructing all of them first (and without repeating permutations, e.g., if you&#8217;ve examined [[2,1], [4,3]] you would not examine [[4,3], [2,1]],  [[2,1], [3,4]] and so on)?.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

