4 ms·
Instead of passing/returning null, there are much clearer things for all your examples, depending on the situation: Optionals, Empty Containers, Errors. Just us
by jerrre 8y ago
Instead of passing/returning null, there are much clearer things for all your examples, depending on the situation: Optionals, Empty Containers, Errors. Just using null communicates very little.
- rini17 8y agoEmpty container isn't much better communication aid, only in some specific situations. Much better would be for VM to save the stack at the "null" value creation time and later attach that stack trace to the NullPointerException. Perhaps it's finally time to adopt this from Lisp :D
- heavenlyblue 8y agoSaid so many times. Do not ever use nulls as flags. It’s incredibly like Python exception handling: it works well until you try to work with a somewhat complex codebase: eg paramiko. The IOErrors can be raised by any layer of the stack. So how do I handle this in the code? Well, turns out I can’t definitely tell one from another. Same is with the null values: never use nulls as a flag unless you’re absolutely sure that null value will not be boxed in another “Optional”.
- tbronchain 8y agoSo your understanding of the pattern #3 is that, null was being used instead of an empty list, and in this case it's better to use an empty container. In that case, it makes sense, that's not how I understood it at first. Oh and, I agree about the not using null thing at multiple levels.