• calcopiritus@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    3 months ago

    I kinda disagree. The reason rust caught on is because it is much safer than C++ while having the same or even better performance. And in some contexts, being garbage collected means bad performance.

    Before rust you could either have a fast language (C/C++) or a memory safe language (any other language. That is, languages with garbage collector). But if you required memory safety and peak performance, there wasn’t any option.

    Yes, the reason that rust is both memory safe and fast is because it has a borrow checker. But the borrow checker is the means, not the end.

    • AnyOldName3@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      3 months ago

      Garbage collection doesn’t guarantee memory safety and it’s perfectly possible to create a memory-safe language without garbage collection. There are plenty of garbage collectors for C++ (and until C++23, support for garbage collection was part of the standard, although no one implemented it), and languages like C# let you interact with garbage-collected objects in unsafe blocks.

      • Decq@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        3 months ago

        Exactly, if garbage collection meant memory safety then why do we get null pointer exceptions about every 5 minutes in Java. Garbage collection is about memory leaks, not safety. Imho the borrow checker is a better solution than garbage collection and faster to boot.

        • calcopiritus@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          3 months ago

          Null safety and memory safety are different features.

          Null safety means that you cannot access a struct’s fields without first checking if the pointer to that struct isn’t null. And this must be a compile-time check.

          Memory safety means that you cannot read or write to/from memory that has been free-ed. Without leaks ofc, otherwise it would be very easy.