3 ms·
By all means, have more clumsy, less straightforward ways to represent the lack of a value in your code, because Tony Hoare says so.
by asveikau 11y ago
By all means, have more clumsy, less straightforward ways to represent the lack of a value in your code, because Tony Hoare says so.
- Peaker 11y agoAn Optional type is more clumsy than null checks and null returns sprinkled everywhere??
- harryh 11y agoThe 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.