<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>An example of why Ruby is no longer my LoC / commentary</title>
  <link href="http://platypope.org/blog/posts/32/comments" rel="self"/>
  <link href="http://platypope.org/blog/2009/7/10/an-example-of-why-ruby-is-no-longer-my-loc" rel="alternate"/>
  <id>urn:uuid:cac75bcc-6da2-11de-8227-aa008bfedbfd</id>
  <updated>2009-07-11T07:34:12-04:00</updated>
  <author>
    <name>Various commentators</name>
  </author>
  <entry>
    <title>Comment on "An example of why Ruby is no longer my LoC"</title>
    <link href="http://platypope.org/blog/2009/7/10/an-example-of-why-ruby-is-no-longer-my-loc#comment177" rel="alternate"/>
    <id>urn:uuid:c17557c4-6e0e-11de-8227-aa008bfedbfd</id>
    <updated>2009-07-11T07:34:12-04:00</updated>
    <author>
      <name>Jason</name>
    </author>
    <content type="html">
&lt;p&gt;Yep, because Ruby is the only language with inconsistent behaviour in it's standard library and core classes...&lt;/p&gt;

&lt;p&gt;You do realize that in Ruby, only false and nil evaluate to 'false' in case/if statements? Thus, you can use zero? nonzero? just fine without ever caring about, or running into, this &amp;quot;feature&amp;quot;.&lt;/p&gt;

&lt;p&gt;Talk about the execution speed, the mediocre garbage collection implementation (both of which are vastly better in 1.9 of course), but a single oddity in a core class? Guess you'd better give up programming completely because this stuff is everywhere.&lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Comment on "An example of why Ruby is no longer my LoC"</title>
    <link href="http://platypope.org/blog/2009/7/10/an-example-of-why-ruby-is-no-longer-my-loc#comment178" rel="alternate"/>
    <id>urn:uuid:8cf88a26-6e21-11de-8227-aa008bfedbfd</id>
    <updated>2009-07-11T09:48:44-04:00</updated>
    <author>
      <name>sneakin</name>
    </author>
    <content type="html">
&lt;p&gt;class Numeric
  def zero?; self == 0; end # 0.0 fun?
  def nonzero?; !zero?; end
end&lt;/p&gt;

&lt;p&gt;There's a fix. Love Ruby's ability to patch things up.&lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Comment on "An example of why Ruby is no longer my LoC"</title>
    <link href="http://platypope.org/blog/2009/7/10/an-example-of-why-ruby-is-no-longer-my-loc#comment179" rel="alternate"/>
    <id>urn:uuid:adb00a88-6e3e-11de-8227-aa008bfedbfd</id>
    <updated>2009-07-11T13:17:14-04:00</updated>
    <author>
      <name>llasram</name>
    </author>
    <content type="html">
&lt;p&gt;@Jason: Fair enough, although I did say &amp;quot;example&amp;quot; not &amp;quot;entire reason.&amp;quot;  I was just at the time annoyed about this one because I was inserting a Boolean value into a database via an interface which (sensibly enough) interpreted &lt;code&gt;nil&lt;/code&gt; as &lt;code&gt;NULL&lt;/code&gt; rather than &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Comment on "An example of why Ruby is no longer my LoC"</title>
    <link href="http://platypope.org/blog/2009/7/10/an-example-of-why-ruby-is-no-longer-my-loc#comment180" rel="alternate"/>
    <id>urn:uuid:0f3dfdb8-6e45-11de-8227-aa008bfedbfd</id>
    <updated>2009-07-11T14:02:55-04:00</updated>
    <author>
      <name>Anton</name>
    </author>
    <content type="html">
&lt;p&gt;@Jason you are wrong IMO, zero IS NOT false - it makes more sense - since 0 it's an object !&lt;/p&gt;

&lt;p&gt;@author of the rant: maybe you can do &lt;/p&gt;

&lt;p&gt;from what I see in the doc, nonzero? is not supposed to return a boolean SO you should do either !!1.nonzero? or !1.zero?&lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Comment on "An example of why Ruby is no longer my LoC"</title>
    <link href="http://platypope.org/blog/2009/7/10/an-example-of-why-ruby-is-no-longer-my-loc#comment181" rel="alternate"/>
    <id>urn:uuid:90c483c6-6e76-11de-8227-aa008bfedbfd</id>
    <updated>2009-07-11T19:57:18-04:00</updated>
    <author>
      <name>john</name>
    </author>
    <content type="html">
&lt;p&gt;@Anton you should do a better job of reading.&lt;/p&gt;

&lt;p&gt;Jason stated nil and false return false in conditionals, NOT zero.&lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Comment on "An example of why Ruby is no longer my LoC"</title>
    <link href="http://platypope.org/blog/2009/7/10/an-example-of-why-ruby-is-no-longer-my-loc#comment182" rel="alternate"/>
    <id>urn:uuid:3ff80370-6e79-11de-8227-aa008bfedbfd</id>
    <updated>2009-07-11T20:16:31-04:00</updated>
    <author>
      <name>Mike</name>
    </author>
    <content type="html">
&lt;p&gt;&amp;quot;false != 0&amp;quot; is not inconsistent, actually its very consistent as &amp;quot;Anton&amp;quot; said.&lt;/p&gt;

&lt;p&gt;about the execution speed.. yes it's slow but ruby 1.9 is faster than perl, php, python.... do you want to bet? ;)&lt;/p&gt;

&lt;p&gt;@sneakin theres no need to patch core classes, thats really bad in my opinion.&lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Comment on "An example of why Ruby is no longer my LoC"</title>
    <link href="http://platypope.org/blog/2009/7/10/an-example-of-why-ruby-is-no-longer-my-loc#comment184" rel="alternate"/>
    <id>urn:uuid:e16cb7b0-6eaf-11de-8227-aa008bfedbfd</id>
    <updated>2009-07-12T02:47:34-04:00</updated>
    <author>
      <name>John Doe</name>
    </author>
    <content type="html">
&lt;p&gt;hmmm, if you are giving up a language because of an inconsistency, you should give up programming as well. Every programming language I have programmed till now has some.&lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Comment on "An example of why Ruby is no longer my LoC"</title>
    <link href="http://platypope.org/blog/2009/7/10/an-example-of-why-ruby-is-no-longer-my-loc#comment185" rel="alternate"/>
    <id>urn:uuid:4f4ea9c4-6fd6-11de-8227-aa008bfedbfd</id>
    <updated>2009-07-13T13:55:11-04:00</updated>
    <author>
      <name>Sean</name>
    </author>
    <content type="html">
&lt;p&gt;@Mike - that's exactly what jason said. 0 is not false, but 1.zero? is, likewise 0.nonzero? returns nil so:
&amp;lt;code&amp;gt;
def why&lt;em&gt;argue&lt;/em&gt;about&lt;em&gt;this?(a&lt;/em&gt;zero = 0, not&lt;em&gt;a&lt;/em&gt;zero = 1)
  if (not&lt;em&gt;a&lt;/em&gt;zero.zero? || a_zero.nonzero?)
    puts &amp;quot;we have a problem&amp;quot;
  else
    puts &amp;quot;what is the problem?&amp;quot;
  end
end
&amp;lt;/code&amp;gt;&lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Comment on "An example of why Ruby is no longer my LoC"</title>
    <link href="http://platypope.org/blog/2009/7/10/an-example-of-why-ruby-is-no-longer-my-loc#comment186" rel="alternate"/>
    <id>urn:uuid:05678320-7040-11de-8227-aa008bfedbfd</id>
    <updated>2009-07-14T02:31:53-04:00</updated>
    <author>
      <name>Piers Cawley</name>
    </author>
    <content type="html">
&lt;p&gt;Who cares if it returns an actual boolean. So long as it returns something boolean enough for if/then, ?: or whatever.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nil&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt; are false-y, everything else is truth-y. So long as you don't do something stupid like &lt;code&gt;if value == true ...&lt;/code&gt; then you'll be fine. Just write &lt;code&gt;if value ...&lt;/code&gt; and be done with it.&lt;/p&gt;

&lt;p&gt;There's plenty of reasons for using something other than ruby, but this one seems like very small beer.&lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Comment on "An example of why Ruby is no longer my LoC"</title>
    <link href="http://platypope.org/blog/2009/7/10/an-example-of-why-ruby-is-no-longer-my-loc#comment187" rel="alternate"/>
    <id>urn:uuid:a455025a-7b0d-11de-8227-aa008bfedbfd</id>
    <updated>2009-07-27T20:28:58-04:00</updated>
    <author>
      <name>bathmat</name>
    </author>
    <content type="html">
&lt;p&gt;it does seem like it should be consistent given that ?-methods generally return boolean. though I never much cared for the #zero? stuff anyway. thing==0 and thing!=0 seem perfectly good. &lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Comment on "An example of why Ruby is no longer my LoC"</title>
    <link href="http://platypope.org/blog/2009/7/10/an-example-of-why-ruby-is-no-longer-my-loc#comment188" rel="alternate"/>
    <id>urn:uuid:2ba21362-8db3-11de-8227-aa008bfedbfd</id>
    <updated>2009-08-20T13:59:13-04:00</updated>
    <author>
      <name>yongbin99</name>
    </author>
    <content type="html">
&lt;p&gt;What is your new language of choice? (come on clojure!)&lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Comment on "An example of why Ruby is no longer my LoC"</title>
    <link href="http://platypope.org/blog/2009/7/10/an-example-of-why-ruby-is-no-longer-my-loc#comment189" rel="alternate"/>
    <id>urn:uuid:26e791d2-b5ed-11de-a749-aa008bfedbfd</id>
    <updated>2009-10-10T18:35:03-04:00</updated>
    <author>
      <name>Shot</name>
    </author>
    <content type="html">
&lt;p&gt;I assume you&#8217;re happy that Numeric#zero? returns the boolean answer whether the object is a zero and unhappy that Numeric#nonzero? does not mirror the behaviour, returning nil or self.&lt;/p&gt;

&lt;p&gt;While I agree this is against the principle of least surprise, Numeric#nonzero? does work as expected in boolean contexts (as nil is falsy and Numeric objects are truthy).&lt;/p&gt;

&lt;p&gt;I don&#8217;t like this discrepancy for idealistic reasons, but there is an argument for it &#8211; nonzero? was explicitely designed to be used in &#8216;spaceship&#8217; methods to simplify their code. Consider an object with three properties with varying importance: pri, sec and ter. nonzero? allows you to write the comparator method like this:&lt;/p&gt;

&lt;p&gt;def &amp;lt;=&amp;gt; other
    (pri &amp;lt;=&amp;gt; other.pri).nonzero? or (sec &amp;lt;=&amp;gt; other.sec).nonzero? or ter &amp;lt;=&amp;gt; other.ter
  end&lt;/p&gt;

&lt;p&gt;Without nonzero? you&#8217;d need more verbose code.&lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Comment on "An example of why Ruby is no longer my LoC"</title>
    <link href="http://platypope.org/blog/2009/7/10/an-example-of-why-ruby-is-no-longer-my-loc#comment190" rel="alternate"/>
    <id>urn:uuid:86fcb284-b677-11de-a749-aa008bfedbfd</id>
    <updated>2009-10-11T11:05:34-04:00</updated>
    <author>
      <name>llasram</name>
    </author>
    <content type="html">
&lt;p&gt;@Shot Your assumption is correct, and your explanation makes sense, but still doesn't justify it for me.  The Ruby convention is that methods ending with '?' are Boolean predicates.  In most contexts, nonzero? returns something which can be implicitly interpreted as Boolean, but causes surprise and unnecessary debugging effort when used in a context where 'false' and 'nil' are not interpreted the same.  So personally I value consistency in these sorts of cases.&lt;/p&gt;    </content>
  </entry>
</feed>
