<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Artful Code &#187; ruby</title>
	<atom:link href="http://www.artfulcode.net/tags/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artfulcode.net</link>
	<description>Resources and tips for dynamic, interactive languages.</description>
	<lastBuildDate>Fri, 09 Sep 2011 02:15:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Why Ruby is an acceptable Perl</title>
		<link>http://www.artfulcode.net/articles/why-ruby-acceptable-perl/</link>
		<comments>http://www.artfulcode.net/articles/why-ruby-acceptable-perl/#comments</comments>
		<pubDate>Fri, 01 Jun 2007 01:56:00 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Soap box]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.artfulcode.net/articles/why-ruby-acceptable-perl/</guid>
		<description><![CDATA[Everyone has read this article. It explains how Ruby&#8217;s enumerable effectively makes it a lisp. Like all we arrogant lispers, I of course disagree. That&#8217;s not to say that Ruby isn&#8217;t a good language, though. It&#8217;s just that it&#8217;s more idiomatic of Perl than Lisp. It does have its big selling point, enumerable. Enumerable is [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone has read <a href="http://www.randomhacks.net/articles/2005/12/03/why-ruby-is-an-acceptable-lisp">this article</a>.  It explains how Ruby&#8217;s enumerable effectively makes it a lisp.  Like all we arrogant lispers, I of course disagree.  That&#8217;s not to say that Ruby isn&#8217;t a good language, though.  It&#8217;s just that it&#8217;s more idiomatic of Perl than Lisp.<span id="more-60"></span></p>
<p>It does have its big selling point, enumerable.  Enumerable is nice.  Blocks are nice, although they are not as powerful as lambdas.  One big selling point that you rarely see mentioned, though, is Perl-style regexp.</p>
<p>Nearly every language can do regular expression matching using Perl-style regular expressions.  However, few have built-in operators for it &#8211; =~ to match an expression and s/foo/bar to modify an expression.  PHP&#8217;s functions, by comparison, are a huge code overhead.  The same is true for Python.  For example, in PHP:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;hello world&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/world/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Jeff&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&#8230;not to mention having to first import the regex library into Python:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
regex = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'world'</span><span style="color: black;">&#41;</span>
x = <span style="color: #483d8b;">&quot;hello world&quot;</span>
x = regex.<span style="color: black;">sub</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Jeff&quot;</span>, x<span style="color: black;">&#41;</span></pre></div></div>

<p>Whereas in Perl you just have:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #0000ff;">$x</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;hello world&quot;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$x</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/world/Jeff/</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ruby has similar syntax and a powerful regexp library.  It also has Perl&#8217;s syntactic freedom &#8211; that is, things can be written in many different ways.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">i = <span style="color:#996600;">&quot;Hello world&quot;</span>
<span style="color:#9966CC; font-weight:bold;">if</span> i == <span style="color:#996600;">&quot;Hello world&quot;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> i
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>or&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">puts</span> i <span style="color:#9966CC; font-weight:bold;">if</span> i == <span style="color:#996600;">&quot;Hello world&quot;</span></pre></div></div>

<p>Functions also do not require parenthesis if the meaning is clear:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">puts</span><span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>or&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;">puts i</pre></div></div>

<p>This is often called &#8220;poetry mode&#8221; by Rubyists.  However, few Rubyists like to compare their language with Perl because Ruby is religiously object oriented, and Perl is more of an example on how not to implement OOP.</p>
<p>But Ruby does have its origins in Perl.  It inherits a lot of features from languages like Smalltalk and lisp, but if you look at a large Ruby program, you begin to see how Perl-like it is.</p>
<p>And that is Ruby&#8217;s biggest problem as well.  As with Perl, syntactic freedom means that the neatness of code is often a product of the mood of the programmer or the deadline.  Coming back to a program after six months can mean hours of analyzing code, trying to figure out what on earth you were thinking when you wrote that.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em>Submit article</em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhy-ruby-acceptable-perl%2F&amp;title=Why+Ruby+is+an+acceptable+Perl" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhy-ruby-acceptable-perl%2F&amp;title=Why+Ruby+is+an+acceptable+Perl" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.dzone.com/links/add.html?description=Why+Ruby+is+an+acceptable+Perl&amp;url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhy-ruby-acceptable-perl%2F&amp;title=Why+Ruby+is+an+acceptable+Perl" rel="nofollow" title="Add to&nbsp;DZone"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/dzone.png" title="Add to&nbsp;DZone" alt="Add to&nbsp;DZone" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhy-ruby-acceptable-perl%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhy-ruby-acceptable-perl%2F&amp;title=Why+Ruby+is+an+acceptable+Perl" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhy-ruby-acceptable-perl%2F&amp;title=Why+Ruby+is+an+acceptable+Perl" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhy-ruby-acceptable-perl%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Why+Ruby+is+an+acceptable+Perl+@+http%3A%2F%2Fwww.artfulcode.net%2Farticles%2Fwhy-ruby-acceptable-perl%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.artfulcode.net/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.artfulcode.net/articles/why-ruby-acceptable-perl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

