<?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"
	>
<channel>
	<title>Comments on: You might be able to stop trying to call methods on nil</title>
	<atom:link href="http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/feed/" rel="self" type="application/rss+xml" />
	<link>http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/</link>
	<description>Ruby.send(:stop, 'messing around')</description>
	<pubDate>Fri, 12 Mar 2010 14:28:20 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Rails Podcast Brasil - Episódio 8</title>
		<link>http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-488</link>
		<dc:creator>Rails Podcast Brasil - Episódio 8</dc:creator>
		<pubDate>Tue, 01 Apr 2008 14:08:30 +0000</pubDate>
		<guid isPermaLink="false">http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-488</guid>
		<description>[...] You might be able to stop trying to call methods on nil [...]</description>
		<content:encoded><![CDATA[<p>[...] You might be able to stop trying to call methods on nil [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MayoButter</title>
		<link>http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-455</link>
		<dc:creator>MayoButter</dc:creator>
		<pubDate>Sun, 09 Mar 2008 21:12:26 +0000</pubDate>
		<guid isPermaLink="false">http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-455</guid>
		<description>Whoops, mistyped. This is what I meant:

@butter.expires.strftime '%m/%d/%Y' rescue nil</description>
		<content:encoded><![CDATA[<p>Whoops, mistyped. This is what I meant:</p>
<p>@butter.expires.strftime &#8216;%m/%d/%Y&#8217; rescue nil</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MayoButter</title>
		<link>http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-454</link>
		<dc:creator>MayoButter</dc:creator>
		<pubDate>Sun, 09 Mar 2008 21:10:56 +0000</pubDate>
		<guid isPermaLink="false">http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-454</guid>
		<description>@butter.expires.strftime = '%m/%d/%Y'</description>
		<content:encoded><![CDATA[<p>@butter.expires.strftime = &#8216;%m/%d/%Y&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MayoButter</title>
		<link>http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-453</link>
		<dc:creator>MayoButter</dc:creator>
		<pubDate>Sun, 09 Mar 2008 21:10:05 +0000</pubDate>
		<guid isPermaLink="false">http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-453</guid>
		<description>Good point. Now that I think of it... I really only use that in views. Especially when calling strftime on dates that might be nil. Like so:

</description>
		<content:encoded><![CDATA[<p>Good point. Now that I think of it&#8230; I really only use that in views. Especially when calling strftime on dates that might be nil. Like so:</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reg Braithwaite</title>
		<link>http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-452</link>
		<dc:creator>Reg Braithwaite</dc:creator>
		<pubDate>Sun, 09 Mar 2008 16:39:37 +0000</pubDate>
		<guid isPermaLink="false">http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-452</guid>
		<description>"object.child_object.other_object.attribute rescue nil"

Ummm... you know this does a LOT MORE than just handle the case where one of the object is nil, correct? This rescues any exception thrown for any reason and silently swallows it.

For example, what if other_object returns an object that is not null but does not have #attribute? NoMethodError, but it has nothing to do with nil. Or what if one of those methods actually performs a query, but your database is not available? Another exception, silently swallowed again.

There's nothing wrong with writing that when you mean "I want to rescue any exception thrown for any reason and return nil without logging it or letting me know what the problem is, even if it's my own programming error."

But if what you mean is to handle cases where one of the receivers in the chain is nil, you might want to consider something a little more specific.

JM2C, I'm obviously biased :-)</description>
		<content:encoded><![CDATA[<p>&#8220;object.child_object.other_object.attribute rescue nil&#8221;</p>
<p>Ummm&#8230; you know this does a LOT MORE than just handle the case where one of the object is nil, correct? This rescues any exception thrown for any reason and silently swallows it.</p>
<p>For example, what if other_object returns an object that is not null but does not have #attribute? NoMethodError, but it has nothing to do with nil. Or what if one of those methods actually performs a query, but your database is not available? Another exception, silently swallowed again.</p>
<p>There&#8217;s nothing wrong with writing that when you mean &#8220;I want to rescue any exception thrown for any reason and return nil without logging it or letting me know what the problem is, even if it&#8217;s my own programming error.&#8221;</p>
<p>But if what you mean is to handle cases where one of the receivers in the chain is nil, you might want to consider something a little more specific.</p>
<p>JM2C, I&#8217;m obviously biased :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MayoButter</title>
		<link>http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-451</link>
		<dc:creator>MayoButter</dc:creator>
		<pubDate>Sun, 09 Mar 2008 15:49:27 +0000</pubDate>
		<guid isPermaLink="false">http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-451</guid>
		<description>I find myself doing this a lot:

object.child_object.other_object.attribute rescue nil

just returns nil if anything in the chain is nil.</description>
		<content:encoded><![CDATA[<p>I find myself doing this a lot:</p>
<p>object.child_object.other_object.attribute rescue nil</p>
<p>just returns nil if anything in the chain is nil.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reg Braithwaite</title>
		<link>http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-449</link>
		<dc:creator>Reg Braithwaite</dc:creator>
		<pubDate>Fri, 07 Mar 2008 21:26:31 +0000</pubDate>
		<guid isPermaLink="false">http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-449</guid>
		<description>She (who must be obeyed?):

Well, languages like Haskell enforce referential transparency, so 1. if you write Person.find(...) twice in the same expression without using Monads, they will always return the same thing, and 2. teh compiler knows this and will optimize things so that you don't actually call the function twice.

 That being said, it is not particularly DRY. In Scheme, I would use a let to introduce a variable limited in scope to the expression.</description>
		<content:encoded><![CDATA[<p>She (who must be obeyed?):</p>
<p>Well, languages like Haskell enforce referential transparency, so 1. if you write Person.find(&#8230;) twice in the same expression without using Monads, they will always return the same thing, and 2. teh compiler knows this and will optimize things so that you don&#8217;t actually call the function twice.</p>
<p> That being said, it is not particularly DRY. In Scheme, I would use a let to introduce a variable limited in scope to the expression.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: she</title>
		<link>http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-448</link>
		<dc:creator>she</dc:creator>
		<pubDate>Fri, 07 Mar 2008 20:54:21 +0000</pubDate>
		<guid isPermaLink="false">http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-448</guid>
		<description>"This cannot be right. After that, it’s a question of what you find readable."

Personally I find using @var is more readable than the RAILSish solution to throw in Foobar.new(:blabla) all over the place.

The problem is, RoR is built with this from the ground up:
  all_people = Person.find(:all)

This is almost native english language. The thing however you miss here is that in ESSENCE, it is still SHORT and TERSE, and this is GOOD.

The less code you write to achieve a goal, all the better.
It allows you to use any abstraction you want.</description>
		<content:encoded><![CDATA[<p>&#8220;This cannot be right. After that, it’s a question of what you find readable.&#8221;</p>
<p>Personally I find using @var is more readable than the RAILSish solution to throw in Foobar.new(:blabla) all over the place.</p>
<p>The problem is, RoR is built with this from the ground up:<br />
  all_people = Person.find(:all)</p>
<p>This is almost native english language. The thing however you miss here is that in ESSENCE, it is still SHORT and TERSE, and this is GOOD.</p>
<p>The less code you write to achieve a goal, all the better.<br />
It allows you to use any abstraction you want.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rails Podcast Brasil - Episdio 8</title>
		<link>http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-447</link>
		<dc:creator>Rails Podcast Brasil - Episdio 8</dc:creator>
		<pubDate>Thu, 06 Mar 2008 20:57:33 +0000</pubDate>
		<guid isPermaLink="false">http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-447</guid>
		<description>[...] You might be able to stop trying to call methods on nil [...]</description>
		<content:encoded><![CDATA[<p>[...] You might be able to stop trying to call methods on nil [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reg Braithwaite</title>
		<link>http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-442</link>
		<dc:creator>Reg Braithwaite</dc:creator>
		<pubDate>Tue, 04 Mar 2008 20:43:51 +0000</pubDate>
		<guid isPermaLink="false">http://ruby.tie-rack.org/54/you-might-be-able-to-stop-trying-to-call-methods-on-nil/#comment-442</guid>
		<description>"what’s wrong with “@person.name if @person?”

isn’t this so ugly? “@person ? @person.name : nil”"

Absolutely nothing, provided you first write:

@person = ...

If you don't have an @person member variable (or person local), then you must choose between creating one just for this one use or finding another way:

Person.find(:first, ... ) &#38;&#38; Person.find(:first, ... ).name

This cannot be right. After that, it's a question of what you find readable. If I don't need @person elsewhere, adding an extra assignment feels a little like the boilerplate "design patterns" I loathe in Java. But that's just me :-)</description>
		<content:encoded><![CDATA[<p>&#8220;what’s wrong with “@person.name if @person?”</p>
<p>isn’t this so ugly? “@person ? @person.name : nil”&#8221;</p>
<p>Absolutely nothing, provided you first write:</p>
<p>@person = &#8230;</p>
<p>If you don&#8217;t have an @person member variable (or person local), then you must choose between creating one just for this one use or finding another way:</p>
<p>Person.find(:first, &#8230; ) &amp;&amp; Person.find(:first, &#8230; ).name</p>
<p>This cannot be right. After that, it&#8217;s a question of what you find readable. If I don&#8217;t need @person elsewhere, adding an extra assignment feels a little like the boilerplate &#8220;design patterns&#8221; I loathe in Java. But that&#8217;s just me :-)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
