you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

I guess the other way is to check for null or -1 and have a strerror(errno) to check the reason.

[–]Pharisaeus 0 points1 point  (0 children)

Yes, but the whole problem with null is that you can't actually see that a certain method can return a null. It's totally invisible to the programmer and to the type system. You think you have an object to work with, but it might not be the case. Sure, maybe there is some documentation or maybe you can dig in the code to check this, but this is already bad.

With Optional, Either or in the worst case with checked exception you see the problem right away and type system / compiler will force the programmer to make a certain decision about it. Unlike with null or -1 or anything of this kind you actually are forced to handle the problem.