C
Claudio Jeker
Hello,
there is one thing in ruby that annoys me most (at least for now).
if 0
puts "true"
end
Yes, I know everything expect nil and false are true but that's probably
the most illogic part of ruby. Because of this stuff like
if flags & 0x01
# do some stuff if flag is set
end
will execute in any case. Perhaps I'm biased because I'm a crazy C hacker
but I can not believe that others do not fall into this trap. I realy like
the clearness of the ruby syntax but this "everything but nil and false is
true" logic is totaly non obvious and annoying.
Why can't there be a to_bool converter for all numerical Classes?
This converter could be used in boolean expressions, 0.to_bool would
return false and all other numbers would return true.
Probably the best way is to extend the Object class where to_bool would
return true. Subclasses may than overload to_bool with a more complex
version. This makes it possible to use .to_bool everywhere where a boolean
expression is expected.
IMO if it looks like a boolean expression it should act like a boolean
expression.
there is one thing in ruby that annoys me most (at least for now).
if 0
puts "true"
end
Yes, I know everything expect nil and false are true but that's probably
the most illogic part of ruby. Because of this stuff like
if flags & 0x01
# do some stuff if flag is set
end
will execute in any case. Perhaps I'm biased because I'm a crazy C hacker
but I can not believe that others do not fall into this trap. I realy like
the clearness of the ruby syntax but this "everything but nil and false is
true" logic is totaly non obvious and annoying.
Why can't there be a to_bool converter for all numerical Classes?
This converter could be used in boolean expressions, 0.to_bool would
return false and all other numbers would return true.
Probably the best way is to extend the Object class where to_bool would
return true. Subclasses may than overload to_bool with a more complex
version. This makes it possible to use .to_bool everywhere where a boolean
expression is expected.
IMO if it looks like a boolean expression it should act like a boolean
expression.