• sushibowl@feddit.nl
    link
    fedilink
    arrow-up
    24
    arrow-down
    1
    ·
    7 months ago

    In my opinion, the article is flawed in several ways:

    Many want to solve this by hard-forking the world’s system code, either by changing C/C++ into something that’s memory-safe, or rewriting everything in Rust.

    We are building a convenient strawman here. The foolish unnamed “many” who wish to rewrite everything in rust shall remain unnamed. But rest assured there are many. In any case, a false dichotomy is presented: rewrite all, or enhance C/C++. In fact a reasonable compromise is possible: rust is perfectly capable of interoperating with the C languages. Large C and C++ projects such as the Linux kernel and Firefox have successfully incorporated rust into their codebase. In this way codebases may be slowly refactored, incorporating safety piecewise.

    The core principle of computer-science is that we need to live with legacy, not abandon it.

    Citation needed. Not abandoning working code is clearly a Good Idea™, but calling it the core principle of all computer science? I would require some further justification.

    This specific feature isn’t in compilers. But gcc and clang already have other similar features. They’ve only been halfway implemented. This feature would be relatively easy to add. I’m currently studying the code to see how I can add it myself. I could just mostly copy what’s done for the alloc_size attribute. But there’s a considerable learning curve, I’d rather just persuade an existing developer of gcc or clang to add the new attributes for me.

    “It would be pretty easy to make. In fact I’m already doing it. But it’s actually quite hard, so I’d rather get someone else to do it” is quite the argument.

    With such features, the gap is relative small, mostly just changing function parameter lists and data structures to link a pointer with its memory-bounds. The refactoring effort would be small, rather than a major rewrite.

    The argument, such as I understand it, goes like this: bounds checking is an aspect of memory safety. We can add automatic bounds checking easily to C. Once it’s there, existing C programs only require minor modifications to compile again. All other memory safety features can be added in a similar way.

    It seems to me that the author underestimates the problem.

    Firstly, bounds checking is indeed only one aspect. Achieving memory safety as exists in rust requires many such features to be added to C. Secondly, it is not necessarily the case that once the compiler detects unsafe code, the fix is always small. Bounds checking is a convenient case for this argument: simply add bounds checks. Refactoring code to remove e.g. data races may not be so simple. Especially so because “crash when an unsafe access is detected” is often not a desirable solution. One must refactor the code such that the unsafe conditions (and the crash) cannot occur.

    Indeed, code written in rust often entirely avoids patterns that are common in C, for the simple fact that they are hard/impossible to write such that they can be proven safe by the compiler. Just because you can add the checks to the compiler doesn’t mean the rest is “easy” or “minor.”

    Lastly, I’m greatly in favor of enabling C programmers to write safer code. That’s a good thing! C code is not going away soon, and they need all the help they can get. However, I believe that the idea that one can gain all the benefits rust offers with a few additions to the C compiler and some refactoring is not likely to be true. And as stated before, a language that offers the features you need is already available and can be integrated into your C project! You could consider using it for your refactoring.

    • lysdexic@programming.devOP
      link
      fedilink
      English
      arrow-up
      2
      arrow-down
      15
      ·
      7 months ago

      In fact a reasonable compromise is possible: rust is perfectly capable of interoperating with the C languages.

      I doubt you work on software for a living, because not only are you arguing a problem in a desperate need for a solution but also no one in their right mind would think it is a good idea to double the tech stacks and development environments and pipelines and everything, and with that greatly increase the cognitive load require to develop even the simplest features, just to… For what exactly? What exactly is your value proposition, and what tradeoffs, if any, you took into account?

      You are free to do whatever you feel like doing in your pet projects. Rewrite them in as many languages you feel like using. In professional settings where managers have to hire people and have time and cash budgets and have to show bugs and features being finished, this sort of nonsense doesn’t fly.

      • flying_sheep@lemmy.ml
        link
        fedilink
        arrow-up
        17
        ·
        7 months ago

        You’re joking right? The person you’re replying to mentioned examples that are doing it, e.g. Firefox.