<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Michele Campeotto: Tag ruby</title>
    <link>http://blog.micampe.it/articles/tag/ruby?tag=ruby</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>I'm not Winston Wolfe.</description>
    <item>
      <title>Ruby and Python: perspectives</title>
      <description>&lt;p&gt;I just realized something interesting.&lt;/p&gt;

&lt;p&gt;In Ruby you mix in modules that add methods to objects that implement interfaces.&lt;/p&gt;

&lt;p&gt;In Python you have functions that you use on objects that implement interfaces.&lt;/p&gt;&lt;p&gt;One easy example are enumerables/iterables: in Ruby, an object is enumerable if it implements the &lt;code&gt;each&lt;/code&gt; method. The object can then mix in &lt;a href="http://www.ruby-doc.org/core/classes/Enumerable.html"&gt;Enumerable&lt;/a&gt; to gain some methods that you can use:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;f = File.new(".bashrc", "r")
lines = f.find_all { |l| l =~ /^[^#]/ }
# or lines = f.grep(/^[^#]/)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In Python, an object is &lt;a href="http://www.python.org/dev/peps/pep-0234/"&gt;iterable&lt;/a&gt; if it implements the &lt;code&gt;__iter__&lt;/code&gt; method, and the language &lt;em&gt;&amp;#8220;knows&amp;#8221;&lt;/em&gt; how to use the iterators:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;f = file(".bashrc", "r")
lines = [ l for l in f if not l.startswith("#") ]
# or lines = filter(lambda l: not l.startswith("#"), f)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;other examples are &lt;code&gt;any&lt;/code&gt; and &lt;code&gt;all&lt;/code&gt;, which incidentally are what started the discussion with &lt;a href="http://fmosca.acx.it"&gt;Francesco&lt;/a&gt; about this:&lt;/p&gt;

&lt;p&gt;In Ruby, the &lt;code&gt;any?&lt;/code&gt; method is added to every enumerable object that mixes in Enumerable:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;lines.any? { |l| l =~ /^#/ }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In Python, &lt;code&gt;any()&lt;/code&gt; is a built-in function (introduced in &lt;a href="http://docs.python.org/whatsnew/whatsnew25.html"&gt;2.5&lt;/a&gt;) which knows how to use any sequence:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;any(l.startswith("#") for l in lines)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So Ruby works from the &lt;em&gt;inside&lt;/em&gt;, and Python from the &lt;em&gt;outside&lt;/em&gt; of objects. I think therefore that the next comparison between the two languages should not be side-by-side, but inside-and-out.&lt;/p&gt;</description>
      <pubDate>Fri, 10 Nov 2006 07:03:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:db3d233b-525c-4b4f-96af-4079ed77cfcc</guid>
      <author>micampe</author>
      <link>http://blog.micampe.it/articles/2006/11/10/ruby-and-python-perspectives</link>
      <category>English</category>
      <category>ruby</category>
      <category>python</category>
      <category>perspective</category>
      <category>style</category>
      <category>philosophy</category>
      <trackback:ping>http://blog.micampe.it/articles/trackback/1064</trackback:ping>
    </item>
    <item>
      <title>There are two kinds of Ruby on Rails enthusiasts in the world</title>
      <description>&lt;p&gt;Warning: pointless rant ahead.&lt;/p&gt;

&lt;p&gt;There are two kinds of Ruby on Rails enthusiasts in the world: those that used Java before and those that used PHP.&lt;/p&gt;

&lt;p&gt;The first kind is amazed by Ruby on Rails because they finally found a smart and easy way to do what they did for &lt;a href="http://www.hibernate.org/"&gt;the&lt;/a&gt; &lt;a href="http://www.springframework.org/"&gt;last&lt;/a&gt; &lt;a href="http://junit.sourceforge.net/"&gt;ten&lt;/a&gt; &lt;a href="http://appfuse.org/"&gt;years&lt;/a&gt;. They found little technically groundbreaking in Rails, mostly a great execution and tight packaging of proven techniques.&lt;/p&gt;

&lt;p&gt;On the other side, people used to PHP found in Rails the promised land: it&amp;#8217;s like if they jumped from procedural to object oriented programming.&lt;/p&gt;

&lt;p&gt;These are the most annoying: they&amp;#8217;ll spend all day telling everybody how great Rails is or how in Rails you never have to solve &lt;em&gt;any&lt;/em&gt; problem. You&amp;#8217;ll even find them commenting in blogs discussing issues with other platforms: &amp;#8220;Rails doesn&amp;#8217;t have this problem&amp;#8221;.&lt;/p&gt;

&lt;p&gt;Most of them couldn&amp;#8217;t write a plain Ruby program outside of Rails, but they&amp;#8217;ll tell you that Ruby is the way of the future and no other languages are needed or worth using. Others are probably frustrated because they&amp;#8217;d really like to use Rails at work and instead they are forced to hack on someone else&amp;#8217;s unmaintainable PHP code.&lt;/p&gt;

&lt;p&gt;Dudes, Ruby on Rails is great, I mean &lt;strong&gt;great&lt;/strong&gt;, but the world will not be counting years Before DHH and After DHH from now on.&lt;/p&gt;</description>
      <pubDate>Sat, 03 Jun 2006 06:03:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:643039fd-c96b-4764-a489-0a616b9aca5a</guid>
      <author>micampe</author>
      <link>http://blog.micampe.it/articles/2006/06/03/there-are-two-kinds-of-ruby-on-rails-enthusiasts-in-the-world</link>
      <category>English</category>
      <category>ruby</category>
      <category>rubyonrails</category>
      <category>rant</category>
      <category>community</category>
      <trackback:ping>http://blog.micampe.it/articles/trackback/211</trackback:ping>
    </item>
  </channel>
</rss>
