Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm expecting core methods to change either, as that would undoubtedly break programs. Incidentally, this would be kinda funny because the argument about your program being written poorly if it fails with such a change would be turned on its head. But, in any event, to pretend that Ruby was a perfectly designed language and couldn't possibly have warts is weird.

Also, I never said "convention over configuration," since there's nothing to configure here. I was talking specifically about the convention of what a "?" should return. In that same quote Matz also says that predicates typically return a boolean value, but it's not required. That seems to both imply and endorse a convention.



> That seems to both imply and endorse a convention.

Sure. The convention endorsed is "should, but not required". That's exactly what happens. A pattern I see often is something along the lines of

   def ssl?(url)
     url.match /^https/
   end
which returns nil in the case the url doesn't start with https and a matchdata object if it does.

   jruby-1.6.8 :092 >      def ssl?(url)
   jruby-1.6.8 :093?>        url.match /^https/
   jruby-1.6.8 :094?>      end
    => nil 
   jruby-1.6.8 :095 > ssl? "https://google.com"
    => #<MatchData "https"> 
   jruby-1.6.8 :096 > ssl? "http://google.com"
    => nil


I think we may be in more agreement than either is letting on. However, in most arguments on this matter, the "should" part seems to just get ignored.

Now in that whole Rails hoopla, it turned into "it's not required and neither defined? nor nonzero? do it," ignoring the whole "should" part. And now people are pointing at Rails as another example, reinforcing their own bias.


I agree with you that it might be nice if you could actually rely on it, but OTOH I have never personally encountered an error caused by a non-boolean predicate.

However, it's not only nonzero? or defined? that don't return boolean values. see http://news.ycombinator.com/item?id=5074676 for more examples. If you read through the core libs documentation you'll find more examples. You just cannot rely on predicates returning true/false in all cases, so you either have to learn not to rely on it at all or learn every example where it doesn't. So just don't rely on it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: