4 ms·
Its not an all the time thing, though. I often use assignment in a condition statement, in Ruby: if value = obj.slow_method puts value end I know I ha
by psadauskas 17y ago
Its not an all the time thing, though. I often use assignment in a condition statement, in Ruby:
if value = obj.slow_method
puts value
end
I know I had several bugs from the assignment back in my days of coding C/Java in college, and early in my career as a PHP developer, but I can't recall having an issue with it since programming in Ruby. Perhaps the language flow or best-practices manage to avoid the cases when that bug is possible.
- regularfry 17y agoIf you make it a habit to always reverse comparisons, then the assignments stick out that much more, and remind you that it is, in fact, intentional.