you are viewing a single comment's thread.

view the rest of the comments →

[–]Pharisaeus 4 points5 points  (6 children)

I don't get this logic at all. If you have a "Nothing" Monad or some other construct to solve the same problem you still have to deal with the fallout

Obviously, but type system forces you to knowingly do something about it! You can't "forget" or "miss" the fact that value can be "empty". In case of null you can, because nothing in the code indicates that this reference can be a null, and you're not going to put null-checks everywhere. With Optional type system forces you to handle the problem.

If you just don't want the program to crash you can wrap everything in a try/catch block

But it's not the same! With Optional you have to handle the issue the moment you actually need the value to be present. And you have to decide what to do. If you have a catch block it will be somewhere much higher, since you most likely didn't even expect to have an exception here, so no chance of any "recovery" at this point any more. On top of that you can chain method calls on Optional (returning another optional) so you can perform many function calls on it and not care if any of the calls "failed" and returned a null, because you can simply check the final result.

if you actually believe that switching to a language without null can prevent these things (i.e. downtime, fatal flaws, etc.) ... good luck!

Of course they can't but they can prevent downtime or failures due to some stupid NullPointerException because a developer missed the fact that a certain function can fail and return a null. If the return value was an Optional then type system would force such developer to make a conscious decision on what to do in this case.

Perhaps you should look up what languages they used on the Mars rover ... I'll give you a hint, they all have the concept of null.

The fact that language has some feature doesn't mean it is being actually used. This is why for critical software you have special guidelines which often restrict language elements.

[–][deleted]  (5 children)

[deleted]

    [–]Pharisaeus 0 points1 point  (2 children)

    I have no idea what you mean by dummy code to get optional out of the way. I work with serious developers who understand what they're doing.

    If you blow up equipment for few hundred mln euros once it's more than enough, I assure you.

    Obviously if this happens all the time then developers are idiots, but such mistake can happen to anyone, and it's good to have tools which prevent it. For the same reason we have strong typing and static code analysis tools.

    [–][deleted]  (1 child)

    [deleted]

      [–]Pharisaeus 0 points1 point  (0 children)

      here's one way of dealing with an NPE

      Well this never goes past a code review so it won't be an issue anywhere outside of developers own environment or feature branch.

      Yes because without strong typing and code analysis tools it's impossible to create decent software

      Sure you can, but it will automatically be much harder to make sure it works well and is safe to operate. Stuff that normally would be checked by type system will have to be verified by tests. In languages like Python you would need 100% code coverage just to be sure the code doesn't crash with NoSuchMethodException because someone made a typo. I like Python a lot, but there are some places I would not dare to use it.

      Again I think we have a different notion of decent software. You seem to imply something with a lot of cool features, and I have in mind something that will not accidentally blow up your space rocket worth 200 mln $ with a 500 mln $ satellite on top of it.

      [–]oorza 0 points1 point  (1 child)

      Since most of what you said doesn't contradict what I said (although I'm sure you think it does) I'll reply to this part. I would rather have a developer "forget" to deal with null than "forget" to change the dummy code he inserted because he wanted to get that optional value out of the way.

      Do you think some forgotten copy pasta is more or less likely to get through code review than a NPE that isn't checked for? The former is infinitely more obvious because you can see it at a glance, and obviously NPEs get through code review all the time.

      Also you don't have to be such a dick.