4 ms·
Not being a ruby programmer, is there a defensive coding idiom that would have prevented this confusion?
by wglb 17y ago
Not being a ruby programmer, is there a defensive coding idiom that would have prevented this confusion?
- rcoder 17y agoYou can always test for nil explicitly. Compare: unless foo # ... foo can be false or nil to reach this branch end unless foo == false # ... this branch is reached unless foo == false end Since terseness is considered such a cardinal virtue amongst Ruby programmers (including myself), however, this kind of issue is often ignored, and difficult to detect unless your tests explicitly check for "truthy" and "non-truthy" values in addition to the true/false literals.
- wglb 17y agoThanks.
- danishgolkonda 17y agotell me in detail
- ionfish 17y agoif object.nil? puts "Object is nil!" else puts "Object is not nil." end
- lsb 17y agoHaskell obviously isn't Ruby, but its Maybe monad, where you have Just the login, or Nothing, looks pretty appealing.