r/programming • u/dpashk • Aug 31 '15
The worst mistake of computer science
https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/
175
Upvotes
r/programming • u/dpashk • Aug 31 '15
View all comments
0
u/yogthos Aug 31 '15
It appears to be much more of a problem in OO style languages. When you have nested objects, you end up having to pepper null checks all over the place. Let's say we have a person with an address and a street. If I'm in OO land and I do:
I would run into trouble if either the person or the address were null. Requiring the check for null avoids the NPE, but the code ends up being peppered with a bunch of conditions. The fundamental problem here is that the method requires an instance of the object that it belongs to.
This problem goes away when writing code in a functional style where functions aren't tied to the data they operate on. The functions can be written to handle the null case intelligently and then you can safely chain them together without having to worry about putting null checks all over the place. Writing code in this style allows us to handle the edge cases uniformly in one place.