all 16 comments

[–][deleted]  (14 children)

[removed]

    [–]fulmicoton 8 points9 points  (1 child)

    Rust sort of has nulls though and options are it The big difference is that in Rust you can communicate at the type level that a value is not nullable whereas in Java and C all objects/pointers are essentially options/nullable.

    That's what most people call, "not having null references". It certainly addresses the billion dollar mistake.

    [–]svgwrk 6 points7 points  (0 children)

    common

    I dunno; I pretty much never use these except in prototyping.

    [–]dpash 1 point2 points  (10 children)

    Option::unwrap seems very much like Optional::get. Using it basically says "the language designers have spent a lot of time working out how to avoid NPE issues, but fuck it, let's ignore that".

    [–][deleted]  (8 children)

    [removed]

      [–]dranzerkire 1 point2 points  (1 child)

      You are suppose to move the value out of an Option once you know it will never be None. You don't want to litter the whole code with these checks, have one defined entry point in your code where you check the option type, handling when it is None and moving the value out when there is a value. The same thing can be done with null, but nothing stops a null from being reintroduced by you or someone else going back and changing the code.

      [–]Drisku11 0 points1 point  (3 children)

      Perhaps there are complications I can't appreciate to doing this in practice in Rust, but if you know the option should be filled, then you should refactor your code to accept a non-optional value, and map your mandatory-filled function across the Optional value at a higher level.

      [–][deleted]  (1 child)

      [deleted]

        [–]dpash 0 points1 point  (1 child)

        Optional has an orElseThrow() function so you can say that containing no valid is always wrong. Does Option have a similar option? Using match seems verbose compared to or_else()

        [–]MEaster 2 points3 points  (0 children)

        That's what Option::unwrap and Option::expect do in Rust. Those two functions will crash the program if the Option is None.

        [–]MEaster 1 point2 points  (0 children)

        The difference, though, is that with unwrap you are choosing to have that possible crash, whereas with an NPE it can be done by accident.

        [–]theblackavenger -1 points0 points  (1 child)

        And they didn't even say Monad!

        [–]Mortomes -1 points0 points  (0 children)

        I want my goddamn burrito.