3 ms·
Because people from normal langs or without cs background expect type cast roundtrip to return original value if temp type can represent any value of source typ
by lostmsu 11y ago
Because people from normal langs or without cs background expect type cast roundtrip to return original value if temp type can represent any value of source type (e.g. string can represent any value of bool)
- StavrosK 11y agoSo someone would expect that an int cast of "2" would be 2? What would an int cast of "a" be?
- dalke 11y agoI'll add to that - In what "normal langs" is this not a problem? What would a C or C++ programmer expect? Because my experience in those languages says "casting" is a meaningless way to understand what's going on. Perl doesn't have bareword true/falue values. Ruby doesn't use "casting", I think. That is, I think the idiomatic way to express this in Ruby is: >> !!true.to_s => true >> !!false.to_s => true