I’m curious how software can be created and evolve over time. I’m afraid that at some point, we’ll realize there are issues with the software we’re using that can only be remedied by massive changes or a complete rewrite.

Are there any instances of this happening? Where something is designed with a flaw that doesn’t get realized until much later, necessitating scrapping the whole thing and starting from scratch?

  • lil@lemy.lol
    link
    fedilink
    arrow-up
    66
    arrow-down
    13
    ·
    9 months ago

    There is some Rust code that needs to be rewritten in C.

    • Lodra@programming.dev
      link
      fedilink
      English
      arrow-up
      20
      arrow-down
      1
      ·
      9 months ago

      Strange. I’m not exactly keeping track. But isn’t the current going in just the opposite direction? Seems like tons of utilities are being rewritten in Rust to avoid memory safety bugs

      • Khanzarate@lemmy.world
        link
        fedilink
        arrow-up
        5
        arrow-down
        7
        ·
        9 months ago

        The more the code is used, the faster it ought to be. A function for an OS kernel shouldn’t be written in Python, but a calculator doesn’t need to be written in assembly, that kind of thing.

        I can’t really speak for Rust myself but to explain the comment, the performance gains of a language closer to assembly can be worth the headache of dealing with unsafe and harder to debug languages.

        Linux, for instance, uses some assembly for the parts of it that need to be blazing fast. Confirming assembly code as bug-free, no leaks, all that, is just worth the performance sometimes.

        But yeah I dunno in what cases rust is faster than C/C++.

          • 0x0@programming.dev
            link
            fedilink
            arrow-up
            6
            arrow-down
            1
            ·
            9 months ago

            C/C++ isn’t

            You’re talking about two languages, one is C, the other is C++. C++ is not a superset of C.

        • Nibodhika@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          9 months ago

          But yeah I dunno in what cases rust is faster than C/C++.

          First of all C and C++ are very different, C is faster than C++. Rust is not intrinsically faster than C in the same way that C is faster than C++, however there’s a huge difference, safety.

          Imagine the following C function:

          void do_something(Person* person);
          

          Are you sure that you can pass NULL? Or that it won’t delete your object? Or delete later? Or anything, you need to know what the function does to be sure and/or perform lots of tests, e.g. the proper use of that function might be something like:

          if( person ) {
            person_uses++;
            do_something(person);
          }
          
          ...
          
          if( --person_uses == 0 )
            free( person )
          
          

          That’s a lot more calls than just calling the function, but it’s also a lot more secure.

          In C++ this is somewhat solved by using smart pointers, e.g.

          void do_something(std::unique_ptr<Person> person);
          void something_else(std::shared_ptr<Person> person);
          

          That’s a lot more secure and readable, but also a lot slower. Rust achieves the C++ level of security and readability using only the equivalent of a single C call by performing pre-compile analysis and making the assembly both fast and secure.

          Can the same thing be done on C? Absolutely, you could use macros instead of ifs and counters and have a very fast and safe code but not easy to read at all. The thing is Rust makes it easy to write fast and safe code, C is faster but safe C is slower, and since you always want safe code Rust ends up being faster for most applications.

        • flying_sheep@lemmy.ml
          link
          fedilink
          arrow-up
          1
          ·
          9 months ago

          Rust is faster than C. Iterators and mutable noalias can be optimized better. There’s still FORTRAN code in use because it’s noalias and therefore faster

    • Spectranox@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      11
      arrow-down
      23
      ·
      edit-2
      9 months ago

      Agree, call me unreasonable or whatever but I just don’t like Rust nor the community behind it. Stop trying to reinvent the wheel! Rust makes everything complicated.

      On the other hand… Zig 😘