top | item 5072610

(no title)

myndpage | 13 years ago

>And worse, the `?` postfix in Ruby normally means the method returns an actual boolean, not a "boolean context"

That's not true. Predicates methods returns Truthy or Falsey values. Not necessarily booleans. See http://blog.leshill.org/blog/2012/03/25/a-question-of-truth....

discuss

order

nirvdrum|13 years ago

To be fair, this was one side of that argument. A lot of people adopted the boolean convention, not the truthy one. And the few examples like "defined?" and "nonzero?" really seem more like quirks than conventions. In five years of doing Ruby, those examples built into the language and the Rails shitstorm are the only places I've seen this truthy convention adopted.

Original intent aside, if your language is prided on convention, then it has to be open to the convention changing.

Xylakant|13 years ago

One of the quotes in the linked blog post is the pretty much official statement of the languages creator. defined? and nonzero? are core language methods and unlikely to change. The fact that many ruby programmers have a misconception about what predicates were supposed to imply is sad, but won't change things. In short: All ruby devs need to learn how predicates were intended or they're in for a surprise.

Btw: The mantra "convention over configuration" is a rails mantra and not a ruby mantra.

halostatue|13 years ago

I have long (6+ years) used truthy values from my predicate methods, and rarely coerce them into explicitly true or false values. (There are times when it's necessary, but these are extremely rare.)