Most active commenters

    ←back to thread

    Pitfalls of Safe Rust

    (corrode.dev)
    168 points pjmlp | 15 comments | | HN request time: 1.08s | source | bottom
    1. sgt ◴[] No.43603859[source]
    Golang might be better for writing robust software, if that is the goal. Robust services that don't go down.
    replies(7): >>43603900 #>>43603904 #>>43604076 #>>43604231 #>>43604239 #>>43605174 #>>43605256 #
    2. NoTeslaThrow ◴[] No.43603900[source]
    Hell, just go full erlang at that point and you get loads of services for "free".
    3. efnx ◴[] No.43603904[source]
    And why is that? I already don’t agree, but I’d love to hear your take.
    replies(1): >>43603989 #
    4. surajrmal ◴[] No.43603989[source]
    Mentioning golang is a rust article comment section is just bait. People just live comparing the two even though it's somewhat boring comparison
    5. pjmlp ◴[] No.43604076[source]
    First they have to improve the memory model due to possible races when sharing slices due to their fat pointers implementation.
    6. neillyons ◴[] No.43604231[source]
    Golang will panic with a runtime error index out of range if you index out of bounds. There doesn't seem to be a nice built in way to do `arr.get(3)` like in Rust.

        slice := []int{1, 2, 3}
        i := slice[3]
        fmt.Println(i)
    7. IshKebab ◴[] No.43604239[source]
    I don't think so. Rust has much stronger typing than Go which allows you to prevent more classes of bugs than just memory errors.

    The coolest one I've heard is that Fuchsia's network stack managed to eliminate deadlocks.

    But even on a basic level Rust has that "if it compiles it works" experience which Go definitely doesn't.

    replies(1): >>43604273 #
    8. Mond_ ◴[] No.43604273[source]
    > The coolest one I've heard is that Fuchsia's network stack managed to eliminate deadlocks.

    Is there a write up on this? That's very cool

    replies(2): >>43604535 #>>43604580 #
    9. diarrhea ◴[] No.43604535{3}[source]
    IIRC it is just having locks with exclusive constructors, which take previous locks’ guards (by ownership?).

    That way you can never lock lock B if you have not received a guard aka lock from lock A prior. Ensured on the type level.

    I suppose doing this at scale is a real challenge.

    replies(1): >>43610342 #
    10. aw1621107 ◴[] No.43604580{3}[source]
    I think that example comes from the talk "Safety in an Unsafe World" [0, slides at 1].

    There are some crates which implement lock ordering as well (e.g., [2, 3]). lock-ordering states it's inspired by the technique discussed in the talk as well, for what it's worth.

    [0]: https://youtu.be/qd3x5MCUrhw?t=1001 (~16:41 in case the timestamp link doesn't work)

    [1]: https://joshlf.com/files/talks/Safety%20in%20an%20Unsafe%20W... (deadlock prevention example starting slide 50)

    [2]: https://github.com/akonradi/lock-ordering

    [3]: https://github.com/alaric/lock_order

    11. adhamsalama ◴[] No.43605174[source]
    That's a weird thing to say about a language that doesn't have null safety.
    replies(1): >>43605497 #
    12. apatheticonion ◴[] No.43605256[source]
    Both have their place but after writing both extensively, I much prefer Rust - despite the pitfalls.

    My biggest critisim of Rust (in comparison to Go) is the lack of a powerful standard library while Go's standard library is outstanding. I would also like to see standardized interfaces in Rust (like AsyncWrite) and in general the async story could be better - though I appreciate the versatility.

    13. int_19h ◴[] No.43605497[source]
    Not to be outdone here, Go introduces multiple null values that are considered distinct, yet they all exhibit the same problem.
    replies(1): >>43675680 #
    14. jelder ◴[] No.43610342{4}[source]
    The general term for this is "Session types." The Par crate is probably the most mature attempt at this to date.

    https://github.com/faiface/par

    15. adhamsalama ◴[] No.43675680{3}[source]
    I'm still new to Go so I don't know much about this other than empty slices. Can you give me some hints?