At 22:08 11/11/2004 +0900, you wrote: >"Jean-Hugues ROBERT" <jean_hugues_robert / yahoo.com> schrieb im Newsbeitrag >news:6.0.1.1.0.20041111082218.040feec0 / pop.mail.yahoo.com... >> Hi, >> >> I think things should stay the way they are, here is >> why. >> >> Things are a little complex about truthness/falseness. >> One has to distinguish the "value" of an object from >> its "truthness". > >I'm not sure whether I follow you here: an object *is* the value. There >is no such thing as a value that is distinct from the object. An object >is interpreted as in boolean contexts according to certain rules (false >and nil => false, all others true); you could call this convention >"truthness", yes. I don't agree. I don't think that an object IS a value. An object is more than a value, it is made of: an identity a value (or state, or attributes, or ...) a behavior Well... that's the way I learned OO. Two objects can sometime have the same "value", this is how == compares for equality. When I draw a line between "object" and "value" it is about those special objects that compare equal to themselves only. These are always immutable objects. For example, no two objects can have the same value 3, because 3 is an immutable integer. The same is true for true, false, nil. On the other hand, two different strings can both be valued "3". So, in my mind, 3 is a value, whereas "3" is an object (whose initial value is "3"). To me values are objects with some semantic restrictions. >> Only nil and false are "false" from a "truthness" >> perspective. All other objects are "true". >> >> For true? and false? to be somehow usefull, I first felt >> that they should relate to the "truthness" of the >> object, not its "value". That is very different from >> nil? (it checks the value of the object, only The nil >> object is nil?). >> >> This leads to: >> class Object >> def true? ; true ; end >> def false? ; not true? ; end >> end >> class NilClass >> def true? ; false ; end >> end >> class FalseClass >> def true? ; false ; end >> end > >You can simplify this to > >class Object > def true?; self end > def false?; not true? end >end > >because it's the standard convention. Basically this adds one level of >indirection (the method call). But then: nil.true? => nil; I was expecting true, xxx? methods should return a boolean I think. >> Usage: 1 - Checking truthness >> if some_thing.true? then >> xxx >> end >> Usage: 2 - Checking value >> if some_thing == true then >> xxx >> end >> >> On the other hand, one may consider that >> checking the value is what matters most, >> versus checking the truthness. > >I never felt the need for "some_thing == true". In which cases do you >need this? I don't. But the original poster may have a different answer I guess. >> This leads to: >> class Object >> def true? ; false ; end >> def false? ; false ; end >> end >> class TrueClass >> def true? ; true ; end >> end >> class FalseClass >> def false? ; true ; end >> end > >You can simplify this, too: > >class Object > def true?; TrueClass === self end > def false?; FalseClass === self end >end I suspect that this is less efficient. My verbose code leverage the efficient method dispatching of the interpreter (versus the additional === test). >> Usage: 1 - Checking the truthness >> if some_thing then >> xxx >> end >> Usage: 2 - Checking the value >> if some_thing.true? then >> xxx >> end >> >> Solution 2 (checking values) leads to >> code that is slightly smaller (less characters). >> Which is probably a good thing by itself. >> However, I think that it is fairly unreadable. > >Yep. I find this quite irritating. When I see "if some_thing.true? >then..." I'd expect the truthness of some_thing to be used, not the >outcome of the test whether some_thing is actually the instance 'true'. > >> As a conclusion, I think that the status quo >> is the best solution. Instead of a hard to >> understand true?/false?, let's keep an explicit >> xxx == true when value matters instead of >> truthness. > >.... or "TrueClass === xxx" for that matter. Yes. Totally agree. > >> My 0.2 Euros. > >Now we got 0.22 EUR. :-) You make my day ;-) >Kind regards > robert Yours, JeanHuguesRobert ------------------------------------------------------------------------- Web: http://hdl.handle.net/1030.37/1.1 Phone: +33 (0) 4 92 27 74 17