Returning None is Evil. I agree. I've always subscribed to the Samurai Principle myself. If you allow nulls to float around you inevitably end up with NPEs. These can be hard to diagnose properly; not only do you not know if null is actually invalid, but if it is, it's often non-trivial to work out where it came from.
Posted to Java by Simon Brunning at November 21, 2007 10:28 AM> If you allow nulls to float around you inevitably end up with NPEs
Er? Python None is not the same as a null. Further, Python doesn't *have* pointers, and thus doesn't have null-pointer errors.
If you have a point here, I don't see it.
In Python, you get an AttributeError instead, but it amounts to the same thing.
And Python has pointers to *exactly* the same extent that Java does.
Posted by: Simon on November 23, 2007 09:12 AMI don't see the big deal between:
try:
obj = somefunc()
except SomeException:
handle_problem
and
obj = somefunc
if obj is None:
handle_problem