<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>opensoul.org - Daily WTF: NilClass#method_missing Comments</title>
  <id>tag:www.opensoul.org,2009:/2008/4/18/daily-wtf-nilclass-method_missing/comments</id>
  <generator version="0.8.0" uri="http://mephistoblog.com">Mephisto Drax</generator>
  <link href="http://www.opensoul.org/2008/4/18/daily-wtf-nilclass-method_missing/comments.xml" rel="self" type="application/atom+xml"/>
  <link href="/2008/4/18/daily-wtf-nilclass-method_missing" rel="alternate" type="text/html"/>
  <updated>2009-05-26T20:15:50Z</updated>
  <entry xml:base="http://www.opensoul.org/">
    <author>
      <name>Josh</name>
    </author>
    <id>tag:www.opensoul.org,2008-04-18:5739:14244</id>
    <published>2009-05-26T20:15:50Z</published>
    <updated>2009-05-26T20:15:50Z</updated>
    <category term="Code"/>
    <link href="http://www.opensoul.org/2008/4/18/daily-wtf-nilclass-method_missing" rel="alternate" type="text/html"/>
    <title>Comment on 'Daily WTF: NilClass#method_missing' by Josh</title>
<content type="html">&lt;p&gt;I think the implementation is meant to mimic how Objective-C works with nil/null.  The cool thing about the core of the idea (returning nil on nil.whatever) is pretty neat in that you dont have to do nil checking.  If you have a decision that includes nil.whatever it will always return false instead of having to do my_nil_object &#38;&#38; my_nil_object.method_i_intended_to_call.&lt;/p&gt;


	&lt;p&gt;Its neat and works in objective c, so&#8230;&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://www.opensoul.org/">
    <author>
      <name>Andrew</name>
    </author>
    <id>tag:www.opensoul.org,2008-04-18:5739:7326</id>
    <published>2008-08-24T03:36:05Z</published>
    <updated>2008-08-24T03:36:05Z</updated>
    <category term="Code"/>
    <link href="http://www.opensoul.org/2008/4/18/daily-wtf-nilclass-method_missing" rel="alternate" type="text/html"/>
    <title>Comment on 'Daily WTF: NilClass#method_missing' by Andrew</title>
<content type="html">&lt;p&gt;Oh.. and the raise/rescue is probably just a cheap way to hook an existing ExceptionNotifier method, yet still allow the page to render without error.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://www.opensoul.org/">
    <author>
      <name>Andrew</name>
    </author>
    <id>tag:www.opensoul.org,2008-04-18:5739:7325</id>
    <published>2008-08-24T03:30:43Z</published>
    <updated>2008-08-24T03:30:43Z</updated>
    <category term="Code"/>
    <link href="http://www.opensoul.org/2008/4/18/daily-wtf-nilclass-method_missing" rel="alternate" type="text/html"/>
    <title>Comment on 'Daily WTF: NilClass#method_missing' by Andrew</title>
<content type="html">&lt;p&gt;Nah, you&#8217;re missing the use case:  sometimes Rails views will 500 due to &#8220;impossible&#8221; data conditions, far away from the bug (and maybe long after the bug has been fixed).  Unless you have an ultra-rich and constantly-running data integrity checker, these unexpected conditions can result in error pages for users when you try to display the username of the owner of a comment on a video belonging to a group owned by a user that might have been deleted.&lt;/p&gt;


	&lt;p&gt;Careful and judicious use of NilClass#method_missing (with good logging and followup) can save a ton of work.  An alternative would be to nil protect &lt;strong&gt;everything&lt;/strong&gt; in views (and then what would you do anyway?  Typically return nil or skip the record entirely, which encourages the bug or data corruption to go unnoticed for far longer than reasonable use of method_missing would).&lt;/p&gt;


	&lt;p&gt;With great power comes great responsibility.  Sure.  I&#8217;d argue that this is a perfect example of a time when, if you&#8217;re being greatly responsible, you can use the great power for great benefit.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://www.opensoul.org/">
    <author>
      <name>Brandon</name>
    </author>
    <id>tag:www.opensoul.org,2008-04-18:5739:6606</id>
    <published>2008-06-24T21:10:19Z</published>
    <updated>2008-06-24T21:10:19Z</updated>
    <category term="Code"/>
    <link href="http://www.opensoul.org/2008/4/18/daily-wtf-nilclass-method_missing" rel="alternate" type="text/html"/>
    <title>Comment on 'Daily WTF: NilClass#method_missing' by Brandon</title>
<content type="html">&lt;p&gt;andrew:&lt;/p&gt;


	&lt;p&gt;I&#8217;ve spent every day of the last 2 years working on Rails apps.  I don&#8217;t know that I&#8217;ve worked on a project yet that I wouldn&#8217;t classify as &#8220;complex&#8221;.&lt;/p&gt;


	&lt;p&gt;Why stop at overriding &lt;code&gt;#method_missing&lt;/code&gt; on &lt;code&gt;NilClass&lt;/code&gt;?  Why not just override it on &lt;code&gt;Object&lt;/code&gt; so that any object responds to any method?  That would make sure that you never get an error message!&lt;/p&gt;


	&lt;p&gt;If your code is hitting a condition where it would raise an error, then it&#8217;s probably not doing what the user expects anyway.  Why pretend like nothing is wrong?  Your users would appreciate if you quit wasting there time and just acknowledged that there is an error and you&#8217;re working on fixing it.&lt;/p&gt;


	&lt;p&gt;Overriding &lt;code&gt;#method_missing&lt;/code&gt; on &lt;code&gt;NilClass&lt;/code&gt; in this manner is simply ridiculous. It is the symptom of poor programming.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://www.opensoul.org/">
    <author>
      <name>andrew</name>
    </author>
    <id>tag:www.opensoul.org,2008-04-18:5739:6605</id>
    <published>2008-06-24T18:38:54Z</published>
    <updated>2008-06-24T18:38:54Z</updated>
    <category term="Code"/>
    <link href="http://www.opensoul.org/2008/4/18/daily-wtf-nilclass-method_missing" rel="alternate" type="text/html"/>
    <title>Comment on 'Daily WTF: NilClass#method_missing' by andrew</title>
<content type="html">&lt;p&gt;Spend enough time with a complex Rails app, and you&#8217;ll understand why this happens.&lt;/p&gt;


	&lt;p&gt;This is often a fairly reasonable thing to do.  Log the event, return nil to (usually) the view rendering code so that the app doesn&#8217;t 500 for your users, &lt;strong&gt;and follow up on the log messages and fix yr damn code&lt;/strong&gt;.  :)&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://www.opensoul.org/">
    <author>
      <name>Brian</name>
    </author>
    <id>tag:www.opensoul.org,2008-04-18:5739:5755</id>
    <published>2008-04-18T21:18:43Z</published>
    <updated>2008-04-18T21:18:43Z</updated>
    <category term="Code"/>
    <link href="http://www.opensoul.org/2008/4/18/daily-wtf-nilclass-method_missing" rel="alternate" type="text/html"/>
    <title>Comment on 'Daily WTF: NilClass#method_missing' by Brian</title>
<content type="html">&lt;p&gt;I completely agree. I found this in LovdByLess (which has been getting a lot of attention lately):&lt;/p&gt;


	&lt;p&gt;http://github.com/stevenbristol/lovd-by-less/tree/master/vendor/plugins/less_monkey_patching/lib/nil.rb&lt;/p&gt;


	&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;WTF&lt;/span&gt;?&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://www.opensoul.org/">
    <author>
      <name>Stephan</name>
    </author>
    <id>tag:www.opensoul.org,2008-04-18:5739:5742</id>
    <published>2008-04-18T07:38:35Z</published>
    <updated>2008-04-18T07:38:35Z</updated>
    <category term="Code"/>
    <link href="http://www.opensoul.org/2008/4/18/daily-wtf-nilclass-method_missing" rel="alternate" type="text/html"/>
    <title>Comment on 'Daily WTF: NilClass#method_missing' by Stephan</title>
<content type="html">&lt;p&gt;The strack trace is always available via &lt;code&gt;caller&lt;/code&gt; anyway.&lt;/p&gt;</content>  </entry>
  <entry xml:base="http://www.opensoul.org/">
    <author>
      <name>Stephan</name>
    </author>
    <id>tag:www.opensoul.org,2008-04-18:5739:5741</id>
    <published>2008-04-18T07:38:14Z</published>
    <updated>2008-04-18T07:38:14Z</updated>
    <category term="Code"/>
    <link href="http://www.opensoul.org/2008/4/18/daily-wtf-nilclass-method_missing" rel="alternate" type="text/html"/>
    <title>Comment on 'Daily WTF: NilClass#method_missing' by Stephan</title>
<content type="html">&lt;p&gt;Apart from the fact the strack trace is always available via &lt;code&gt;caller&lt;/code&gt;.&lt;/p&gt;</content>  </entry>
</feed>
