<?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: Rubybashing: Why use implicit return?</title>
	<atom:link href="http://amazing-development.com/archives/2006/04/04/rubybashing-why-use-implicit-return/feed/" rel="self" type="application/rss+xml" />
	<link>http://amazing-development.com/archives/2006/04/04/rubybashing-why-use-implicit-return/</link>
	<description>ruby, java and the rest</description>
	<lastBuildDate>Mon, 05 Dec 2011 11:57:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: zenspider</title>
		<link>http://amazing-development.com/archives/2006/04/04/rubybashing-why-use-implicit-return/comment-page-1/#comment-611</link>
		<dc:creator>zenspider</dc:creator>
		<pubDate>Thu, 06 Apr 2006 23:42:48 +0000</pubDate>
		<guid isPermaLink="false">http://amazing-development.com/archives/2006/04/04/rubybashing-why-use-implicit-return/#comment-611</guid>
		<description>Ignoring these wanna-be lispers... :P

One thing to note is that the implicit return is (slightly-but-measurably) faster than the explicit return.&lt;!-- X-spaminator-passed: IP check --&gt;&lt;!-- X-spaminator-passed: email check --&gt;&lt;!-- X-spaminator-passed: author check --&gt;&lt;!-- X-spaminator-passed: author url --&gt;&lt;!-- X-spaminator-passed: comment body --&gt;&lt;!-- X-spaminator-strike: url dashes, 3 --&gt;</description>
		<content:encoded><![CDATA[<p>Ignoring these wanna-be lispers&#8230; <img src='http://amazing-development.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>One thing to note is that the implicit return is (slightly-but-measurably) faster than the explicit return.<!-- X-spaminator-passed: IP check --><!-- X-spaminator-passed: email check --><!-- X-spaminator-passed: author check --><!-- X-spaminator-passed: author url --><!-- X-spaminator-passed: comment body --><!-- X-spaminator-strike: url dashes, 3 --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kartik Vaddadi</title>
		<link>http://amazing-development.com/archives/2006/04/04/rubybashing-why-use-implicit-return/comment-page-1/#comment-603</link>
		<dc:creator>Kartik Vaddadi</dc:creator>
		<pubDate>Wed, 05 Apr 2006 05:13:14 +0000</pubDate>
		<guid isPermaLink="false">http://amazing-development.com/archives/2006/04/04/rubybashing-why-use-implicit-return/#comment-603</guid>
		<description>The &quot;programs are composed of expressions&quot; view can also increase readability. Here are a couple examples:
def fact(n)
&#160;&#160;if n ==0
&#160;&#160;&#160;&#160;1
&#160;&#160;else n * fact(n-1)
&#160;&#160;end
end

Also I find this:

if cond
&#160;&#160;temp = foo
else temp = bar
end
temp.some_complicated_expr

less readable than:

(if cond
&#160;&#160;foo
 else bar
 end).some_complicated_expr</description>
		<content:encoded><![CDATA[<p>The &#8220;programs are composed of expressions&#8221; view can also increase readability. Here are a couple examples:<br />
def fact(n)<br />
&nbsp;&nbsp;if n ==0<br />
&nbsp;&nbsp;&nbsp;&nbsp;1<br />
&nbsp;&nbsp;else n * fact(n-1)<br />
&nbsp;&nbsp;end<br />
end</p>
<p>Also I find this:</p>
<p>if cond<br />
&nbsp;&nbsp;temp = foo<br />
else temp = bar<br />
end<br />
temp.some_complicated_expr</p>
<p>less readable than:</p>
<p>(if cond<br />
&nbsp;&nbsp;foo<br />
 else bar<br />
 end).some_complicated_expr</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Emmett Shear</title>
		<link>http://amazing-development.com/archives/2006/04/04/rubybashing-why-use-implicit-return/comment-page-1/#comment-602</link>
		<dc:creator>Emmett Shear</dc:creator>
		<pubDate>Wed, 05 Apr 2006 02:57:25 +0000</pubDate>
		<guid isPermaLink="false">http://amazing-development.com/archives/2006/04/04/rubybashing-why-use-implicit-return/#comment-602</guid>
		<description>The really big win you get from implicit return isn&#039;t in functions like the one you gave as an example, it&#039;s in functions like this:

def collect_times_two(array)
&#160;&#160;array.collect{ &#124;x&#124; x*2 }
end

With required returns, this elegant looking piece of code turns into:

def collect_times_two(array)
&#160;&#160;return array.collect{ &#124;x&#124; return x*2 }
end

which is definitely less readable.&lt;!-- X-spaminator-passed: IP check --&gt;&lt;!-- X-spaminator-passed: email check --&gt;&lt;!-- X-spaminator-passed: author check --&gt;&lt;!-- X-spaminator-strike: empty field - author url, 1 --&gt;&lt;!-- X-spaminator-passed: author url --&gt;&lt;!-- X-spaminator-passed: comment body --&gt;</description>
		<content:encoded><![CDATA[<p>The really big win you get from implicit return isn&#8217;t in functions like the one you gave as an example, it&#8217;s in functions like this:</p>
<p>def collect_times_two(array)<br />
&nbsp;&nbsp;array.collect{ |x| x*2 }<br />
end</p>
<p>With required returns, this elegant looking piece of code turns into:</p>
<p>def collect_times_two(array)<br />
&nbsp;&nbsp;return array.collect{ |x| return x*2 }<br />
end</p>
<p>which is definitely less readable.<!-- X-spaminator-passed: IP check --><!-- X-spaminator-passed: email check --><!-- X-spaminator-passed: author check --><!-- X-spaminator-strike: empty field - author url, 1 --><!-- X-spaminator-passed: author url --><!-- X-spaminator-passed: comment body --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Avdi</title>
		<link>http://amazing-development.com/archives/2006/04/04/rubybashing-why-use-implicit-return/comment-page-1/#comment-601</link>
		<dc:creator>Avdi</dc:creator>
		<pubDate>Tue, 04 Apr 2006 17:13:00 +0000</pubDate>
		<guid isPermaLink="false">http://amazing-development.com/archives/2006/04/04/rubybashing-why-use-implicit-return/#comment-601</guid>
		<description>A subtle point is that implicit and explicit return can have different semantics.  In the following example:

def pig_out(bushel)
&#160;bushel.map do &#124;fruit&#124;
&#160;&#160;eat(fruit)
&#160;&#160;if sick? then
&#160;&#160;&#160;return &quot;this #{fruit} is bad!&quot;
&#160;&#160;end
&#160;&#160;&quot;this #{fruit} is delicious!
&#160;end
end

If all the fruit are good, then the result of #pig_out will be a list of strings like &quot;this ... is delicious!&quot;.  If there&#039;s a bad apple in the bushel, however, the result of #pig_out will be a single string &quot;this apple is bad!&quot;.  When &quot;return&quot; is used, it tells Ruby to abandon whatever it was doing and immediately return from the containing method.  The semantics of return are just like those of the &quot;throw&quot; kernel method.

So it may be that the reason a lot of Ruby code eschews &quot;return&quot; is because, since it is a more &quot;drastic&quot; operation, it is reserved for the special cases when it is genuinely required.</description>
		<content:encoded><![CDATA[<p>A subtle point is that implicit and explicit return can have different semantics.  In the following example:</p>
<p>def pig_out(bushel)<br />
&nbsp;bushel.map do |fruit|<br />
&nbsp;&nbsp;eat(fruit)<br />
&nbsp;&nbsp;if sick? then<br />
&nbsp;&nbsp;&nbsp;return &#8220;this #{fruit} is bad!&#8221;<br />
&nbsp;&nbsp;end<br />
&nbsp;&nbsp;&#8221;this #{fruit} is delicious!<br />
&nbsp;end<br />
end</p>
<p>If all the fruit are good, then the result of #pig_out will be a list of strings like &#8220;this &#8230; is delicious!&#8221;.  If there&#8217;s a bad apple in the bushel, however, the result of #pig_out will be a single string &#8220;this apple is bad!&#8221;.  When &#8220;return&#8221; is used, it tells Ruby to abandon whatever it was doing and immediately return from the containing method.  The semantics of return are just like those of the &#8220;throw&#8221; kernel method.</p>
<p>So it may be that the reason a lot of Ruby code eschews &#8220;return&#8221; is because, since it is a more &#8220;drastic&#8221; operation, it is reserved for the special cases when it is genuinely required.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank Spychalski</title>
		<link>http://amazing-development.com/archives/2006/04/04/rubybashing-why-use-implicit-return/comment-page-1/#comment-600</link>
		<dc:creator>Frank Spychalski</dc:creator>
		<pubDate>Tue, 04 Apr 2006 13:07:46 +0000</pubDate>
		<guid isPermaLink="false">http://amazing-development.com/archives/2006/04/04/rubybashing-why-use-implicit-return/#comment-600</guid>
		<description>I understand, why it&#039;s a neat thing if every operation returns something, but I still find it hard to read such code. I guess you are right, this is probably due to the lack of functional programming in my past.&lt;!-- X-spaminator-strike: whitelist, -3 --&gt;&lt;!-- X-spaminator-passed: IP check --&gt;&lt;!-- X-spaminator-passed: email check --&gt;&lt;!-- X-spaminator-passed: author url --&gt;&lt;!-- X-spaminator-passed: comment body --&gt;&lt;!-- X-spaminator-strike: url dashes, 1 --&gt;</description>
		<content:encoded><![CDATA[<p>I understand, why it&#8217;s a neat thing if every operation returns something, but I still find it hard to read such code. I guess you are right, this is probably due to the lack of functional programming in my past.<!-- X-spaminator-strike: whitelist, -3 --><!-- X-spaminator-passed: IP check --><!-- X-spaminator-passed: email check --><!-- X-spaminator-passed: author url --><!-- X-spaminator-passed: comment body --><!-- X-spaminator-strike: url dashes, 1 --></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: asdf</title>
		<link>http://amazing-development.com/archives/2006/04/04/rubybashing-why-use-implicit-return/comment-page-1/#comment-599</link>
		<dc:creator>asdf</dc:creator>
		<pubDate>Tue, 04 Apr 2006 12:29:29 +0000</pubDate>
		<guid isPermaLink="false">http://amazing-development.com/archives/2006/04/04/rubybashing-why-use-implicit-return/#comment-599</guid>
		<description>Yes, you are missing something. 

It is an attempt to remedy the problem mentioned here, in point #6
http://www.paulgraham.com/diff.html

&quot;6. Programs composed of expressions. Lisp programs are trees of expressions, each of which returns a value. (In some Lisps expressions can return multiple values.) This is in contrast to Fortran and most succeeding languages, which distinguish between expressions and statements.

It was natural to have this distinction in Fortran because (not surprisingly in a language where the input format was punched cards) the language was line-oriented. You could not nest statements. And so while you needed expressions for math to work, there was no point in making anything else return a value, because there could not be anything waiting for it.

This limitation went away with the arrival of block-structured languages, but by then it was too late. The distinction between expressions and statements was entrenched. It spread from Fortran into Algol and thence to both their descendants.&quot;

You clearly have grown up in a Fortran-derived world. The guy who created Ruby actually knows other languages, and must think they are somehow superior for not having this arbitrary limitation.

When a language is made entirely of expressions, you can compose expressions however you want. You can say either (using Arc syntax)

(if foo (= x 1) (= x 2))

or

(= x (if foo 1 2))&lt;!-- X-spaminator-passed: IP check --&gt;&lt;!-- X-spaminator-strike: excessive links, 3 --&gt;&lt;!-- X-spaminator-passed: email check --&gt;&lt;!-- X-spaminator-passed: author check --&gt;&lt;!-- X-spaminator-strike: empty field - author url, 1 --&gt;&lt;!-- X-spaminator-passed: author url --&gt;&lt;!-- X-spaminator-passed: comment body --&gt;</description>
		<content:encoded><![CDATA[<p>Yes, you are missing something. </p>
<p>It is an attempt to remedy the problem mentioned here, in point #6<br />
<a href="http://www.paulgraham.com/diff.html" rel="nofollow">http://www.paulgraham.com/diff.html</a></p>
<p>&#8220;6. Programs composed of expressions. Lisp programs are trees of expressions, each of which returns a value. (In some Lisps expressions can return multiple values.) This is in contrast to Fortran and most succeeding languages, which distinguish between expressions and statements.</p>
<p>It was natural to have this distinction in Fortran because (not surprisingly in a language where the input format was punched cards) the language was line-oriented. You could not nest statements. And so while you needed expressions for math to work, there was no point in making anything else return a value, because there could not be anything waiting for it.</p>
<p>This limitation went away with the arrival of block-structured languages, but by then it was too late. The distinction between expressions and statements was entrenched. It spread from Fortran into Algol and thence to both their descendants.&#8221;</p>
<p>You clearly have grown up in a Fortran-derived world. The guy who created Ruby actually knows other languages, and must think they are somehow superior for not having this arbitrary limitation.</p>
<p>When a language is made entirely of expressions, you can compose expressions however you want. You can say either (using Arc syntax)</p>
<p>(if foo (= x 1) (= x 2))</p>
<p>or</p>
<p>(= x (if foo 1 2))<!-- X-spaminator-passed: IP check --><!-- X-spaminator-strike: excessive links, 3 --><!-- X-spaminator-passed: email check --><!-- X-spaminator-passed: author check --><!-- X-spaminator-strike: empty field - author url, 1 --><!-- X-spaminator-passed: author url --><!-- X-spaminator-passed: comment body --></p>
]]></content:encoded>
	</item>
</channel>
</rss>

