3 ms·
The problem with NULL is that it can be there for literally any reference in your code. So, unless you are careful, you can get an NPE when calling any single o
by harryh 11y ago
The problem with NULL is that it can be there for literally any reference in your code. So, unless you are careful, you can get an NPE when calling any single object method. In languages without NULL this can never happen making them much easier to reason about.
- cam- 11y agoA NullPointerException is unchecked as well. I would say about 40% of our code is checking for null to avoid NPEs especially with APIs. You have to protect yourself and cannot take nothing for granted.
- asveikau 11y agoMy initial reaction: programming ain't bean bag. Them's the breaks. Then I think of it and I see the real problem is languages making all nonprimitive types into pointers without being explicit. In a language like C it's more obvious what can be null.
- harryh 11y agoIf null can be problematic then certainly making it more obvious when you might have a null is a pretty good idea. I tend to think, however, that getting rid of null completely as a concept is even better. One less thing to worry about.