<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>andthennothing.net: Picking up the axe</title>
  <subtitle type="html">&amp;ldquo;first there was a three-legged monkey...&amp;rdquo;</subtitle>
  <id>tag:andthennothing.net,2005:Typo</id>
  <generator uri="http://typo.leetsoft.com" version="4.0">Typo</generator>
  <link href="http://andthennothing.net/xml/atom10/article/29/feed.xml" rel="self" type="application/xml+atom"/>
  <link href="http://andthennothing.net/archives/2005/08/29/picking-up-the-axe" rel="alternate" type="text/html"/>
  <updated>2007-02-01T07:11:31+00:00</updated>
  <entry>
    <author>
      <name>Jonas Bengtsson</name>
      <email>jonas.b@home.se</email>
    </author>
    <id>urn:uuid:50d5b9d8-bea9-4781-bfd4-d333db7953c4</id>
    <published>2005-08-29T00:42:00+00:00</published>
    <updated>2007-02-01T07:11:31+00:00</updated>
    <title>Picking up the axe</title>
    <link href="http://andthennothing.net/archives/2005/08/29/picking-up-the-axe" rel="alternate" type="text/html"/>
    <category term="ruby" scheme="http://andthennothing.net/tags/29"/>
    <category term="python" scheme="http://andthennothing.net/tags/29"/>
    <category term="rails" scheme="http://andthennothing.net/tags/29"/>
    <category term="book" scheme="http://andthennothing.net/tags/29"/>
    <category term="blocks" scheme="http://andthennothing.net/tags/29"/>
    <content type="html">&lt;p&gt;It&amp;#8217;s been a while since I&amp;#8217;ve been coding &lt;a href="http://ruby-lang.org/en/"&gt;Ruby&lt;/a&gt;. I learned the basics back in &lt;a href="http://andthennothing.net/archives/2002/06/30/ruby"&gt;2002&lt;/a&gt; but since I&amp;#8217;m much more fluent in &lt;a href="http://www.python.org/"&gt;Python&lt;/a&gt; I very rarely use Ruby when I need something done. But this time I have the motivation of &lt;a href="http://www.rubyonrails.org/"&gt;Rails&lt;/a&gt; and a newly bought &lt;a href="http://www.pragmaticprogrammer.com/titles/ruby/"&gt;Programming Ruby 2nd edition&lt;/a&gt; (a.k.a. PickAxe).&lt;/p&gt;


	&lt;p&gt;Now to some random incoherent things I&amp;#8217;ve learned about Ruby recently.&lt;/p&gt;


	&lt;p&gt;The most important and interesting aspect of the language, &lt;span class="caps"&gt;IMHO&lt;/span&gt;, is &lt;a href="http://www.rubyist.net/~matz/slides/oscon2005/"&gt;blocks&lt;/a&gt;, and I think I grok it now and am able to know when to apply them.&lt;/p&gt;


	&lt;p&gt;There were two conventions that made Rails-code hard for me to understand before: symbols and e.g. &lt;tt&gt;belongs_to&lt;/tt&gt;. &lt;a href="http://glu.ttono.us/articles/2005/08/19/understanding-ruby-symbols"&gt;Kevin Clark taught me symbols&lt;/a&gt; and this piece of code describes how &lt;tt&gt;belongs_to&lt;/tt&gt; &lt;em&gt;et al.&lt;/em&gt; work:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;tinker_with_class&lt;/span&gt;
  &lt;span class="ident"&gt;class_eval&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt;
    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;hello&lt;/span&gt;
      &lt;span class="ident"&gt;puts&lt;/span&gt; &lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;Hello world!&lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;

&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Hello&lt;/span&gt;
  &lt;span class="ident"&gt;tinker_with_class&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;

&lt;span class="ident"&gt;h&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Hello&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;
&lt;span class="ident"&gt;h&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;hello&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Output: Hello world!&lt;/p&gt;


	&lt;p&gt;One thing that I wasn&amp;#8217;t aware of before was that &lt;tt&gt;Range&lt;/tt&gt; supports custom classes (implementing the &lt;tt&gt;succ&lt;/tt&gt; and &lt;tt&gt;&lt;=&gt;&lt;/tt&gt; methods), which is neat and something that Python lacks.&lt;/p&gt;


	&lt;p&gt;Mixins seems to be a really good means of reuse, but I don&amp;#8217;t know that much about them for a couple of chapters.&lt;/p&gt;


	&lt;p&gt;Private methods and variables can only be accessed by the own object, i.e. you can&amp;#8217;t access private methods and variables of objects of the same class (as you can in Python, C++, Java and most other languages).&lt;/p&gt;


	&lt;p&gt;Many of the Perlisms seems to be less preferred now than the first edition of the PickAxe, which is a good thing. Who wants to remember the difference between &lt;tt&gt;$!&lt;/tt&gt;, &lt;tt&gt;$&amp;#38;&lt;/tt&gt;, &lt;tt&gt;$.&lt;/tt&gt;, &lt;tt&gt;$_&lt;/tt&gt;, &lt;tt&gt;$~&lt;/tt&gt; etc?&lt;/p&gt;


	&lt;p&gt;The main gripe I have is that &lt;tt&gt;irb&lt;/tt&gt; doesn&amp;#8217;t work that well with Swedish keyboard layout on Windows, which is a shame since interactive Python was instrumental in my learning of Python.&lt;/p&gt;


	&lt;p&gt;Anyhow, I like most aspects of Ruby and I hope it will become as natural to me as Python.&lt;/p&gt;</content>
  </entry>
</feed>
