• Croquette@sh.itjust.works
    link
    fedilink
    arrow-up
    21
    arrow-down
    2
    ·
    1 day ago

    Where would you say Rust isn’t the right solution?

    We always hear how great Rust is, but I’d be curious to know where it isn’t.

    • brucethemoose@lemmy.world
      link
      fedilink
      arrow-up
      14
      ·
      edit-2
      1 day ago

      I great example I saw is a dev who was building on a Rust game (with the Bevy engine), and switched to Unity.

      https://deadmoney.gg/news/articles/migrating-away-from-rust

      Collaboration - I started this project with my brother. While he’s sharp and eager, he’s new to coding. Onboarding him directly into game dev while simultaneously navigating Rust’s unique aspects proved challenging. We found ourselves with a steeper learning curve that slowed his ability to contribute effectively to gameplay logic.

      Abstraction - While my initial motivation was the enjoyment of Rust, the project’s bottleneck increasingly became the rapid iteration of higher-level gameplay mechanics. As the codebase grew, we found that translating gameplay ideas into code was less direct than we hoped. Rust’s (powerful) low-level focus didn’t always lend itself to a flexible high-level scripting style needed for rapid prototyping within our specific gameplay architecture. I found that my motivation to build and ship fun gameplay was stronger than my desire to build with Rust.

      Migration - Bevy is young and changes quickly. Each update brought with it incredible features, but also a substantial amount of API thrash. As the project grew in size, the burden of update migration also grew. Minor regressions were common in core Bevy systems (such as sprite rendering), and these led to moments of significant friction and unexpected debugging effort. This came to a head on one specific day where I was frustrated with a sprite rendering issue that had emerged in a new release. Blake had run into the same problem at the same time and our shared frustration boiled over into a kind of table flip moment. He turned to me and said something along the lines of “this shouldn’t happen, this kind of thing should just be solved” and that triggered the conversation that led to a re-evaluation. The point isn’t that specific sprite problem, but that because all systems in Bevy are open to tinkering and improvement, all systems were potentially subject to regressions.

      Learning - Over the past year my workflow has changed immensely, and I regularly use AI to learn new technologies, discuss methods and techniques, review code, etc. The maturity and vast amount of stable historical data for C# and the Unity API mean that tools like Gemini consistently provide highly relevant guidance. While Bevy and Rust evolve rapidly - which is exciting and motivating - the pace means AI knowledge lags behind, reducing the efficiency gains I have come to expect from AI assisted development. This could change with the introduction of more modern tool-enabled models, but I found it to be a distraction and an unexpected additional cost.

      Modding - Modding means a lot to me. I got my start in the industry as a modder and I want my game to be highly moddable. Over time, as I learned more about how to realize this goal, I came to understand many inherent limitations in Rust and Bevy that would make the task more difficult. Lack of a clear solution to scripting and an unstable ABI (application binary interface) raised concerns. I am not an expert in this area, perhaps these are all easily surmounted. I can only say that I did not find a path (after much searching) that I felt confident trusting.

      It sounds like Rust (game engines, and more) could use a higher level scripting language, or integrate an existing one, I guess.

      • dejected_warp_core@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        18 hours ago

        Rust […] could use a higher level scripting language, or integrate an existing one, I guess.

        One approach is to use more macros. These are still rooted in the core Rust language, so they give up none of the compile-time checks required for stability. The tradeoff is more complex debugging, as it’s tough to implement a macro without side effects and enough compile-time feedback that you’d expect from a DSL.

        Another is to, as you suggest, embed something. For example, Rust has Lua bindings. One could also turn things inside out and refactor the rust program (or large portions of it) as a Python module.

      • Croquette@sh.itjust.works
        link
        fedilink
        arrow-up
        8
        ·
        1 day ago

        I interface with low level communication protocols, mostly uart, so it fits my use case. But it is nice to see the hurdles people encounters. It tells a lot about the language.

        • brucethemoose@lemmy.world
          link
          fedilink
          arrow-up
          5
          ·
          edit-2
          1 day ago

          Yeah. I wasn’t trying to imply it’s a bad language at all; it just fits certain use cases. They are complex, like people.

          Still, it seems like it’d be cool for engine work, with C# or maybe a subset of typed Python as a scripting language.

    • rumba@lemmy.zip
      link
      fedilink
      English
      arrow-up
      24
      ·
      1 day ago

      Rust provides safety and protection.

      Rust isn’t as rapid as other options, has less library support, and porting existing code is relatively difficult.

      IMO because of the workarounds you need to do to handle the memory safety, you end up with a lot more hard to solve bugs than you do with conventional languages. It should be noted however that the bugs don’t end up being security vulnerabilities like they do in conventional systems.

      If you have something that needs to be structurally sound and/or you have enough talented people willing to work on it, it’s a great option. If it needs to be fast and cheap and you don’t have a gaggle of rust developers on hand and it’s already written in another language, it might not be the best solution.

      • Croquette@sh.itjust.works
        link
        fedilink
        arrow-up
        5
        ·
        1 day ago

        I come from embedded C, so what you describe doesn’t feel alien to me (minus the security vulnerabilities haha)

        I much prefer working with Rust restrictions than a higher level language without hard types because I am used to it.

      • Limaj@techhub.social
        link
        fedilink
        arrow-up
        1
        arrow-down
        3
        ·
        1 day ago

        @rumba @Croquette They’re is a lot of people scrambling to rewrite existing c projects in rust for what?
        for example ffmpegs rust rewrite is slower than the c version we need more maintainers rather than creating new rust alternatives that have no purpose

        • rumba@lemmy.zip
          link
          fedilink
          English
          arrow-up
          9
          ·
          1 day ago

          If you want to ignore re-making things out of memory-safe technology as an advancement, we don’t really have anything to talk about here.

          • Limaj@techhub.social
            link
            fedilink
            arrow-up
            0
            arrow-down
            1
            ·
            1 day ago

            @rumba making new projects in rust sure cool but when big projects that most of the world relies on etc ffmpeg crucially need maintainers and contributions rust isnt needed and is a waste of resources when C can do it better, faster and easier rust is a fast fade that will likely remain in the shadow of C. Tbh your glazing rust without looking at both sides of the argument so the picture op posted really is true

            • rumba@lemmy.zip
              link
              fedilink
              English
              arrow-up
              1
              ·
              18 hours ago

              Ahem…

              If you want to ignore re-making things out of memory-safe technology as an advancement, we don’t really have anything to talk about here.

        • Croquette@sh.itjust.works
          link
          fedilink
          arrow-up
          1
          ·
          1 day ago

          I know Rust superficially. I use it to create simple tests for my embedded projects, so mostly just serial terminal with keyboard inputs.

          It works a lot better for me than python because Rust is a lot closer to C than python.

          So I cannot comment on Rust shortcomings. I was interested in knowing for what kind of projects Rust wasn’t good.

    • NeatNit@discuss.tchncs.de
      link
      fedilink
      arrow-up
      9
      arrow-down
      1
      ·
      1 day ago

      Never used Rust but I’d like to point out the YouTube channel Low Level which covers security vulnerabilities (CVEs). He ends each video with “would Rust have fixed this?” and it’s pretty interesting.

      A very recent one is this: https://youtu.be/BTjj1ILCwRs?t=10m (timestamped to the relevant section)

      According to him, when writing embedded software in Rust (and UEFI is embedded), you have to use Rust in unsafe mode which basically disables all the memory safety features. So in that kind of environment Rust isn’t really better than C, at least when it comes to memory safety.

      That’s not to say Rust isn’t still a good option. It probably is.

      Again, I never used Rust so I’m just parroting stuff I’ve heard, take all of this with a grain of salt.

      • calcopiritus@lemmy.world
        link
        fedilink
        arrow-up
        12
        ·
        1 day ago

        Rust doesn’t have “safe” and “unsafe” modes in the sense your comment alludes to.

        You can just do the little unsafe thing in a function that guarantees its safety, and then the rest of the code is safe.

        For example, using C functions from rust is unsafe, but most of the time a simple wrapper can be made safe.

        Example C function:

        int arraysum(const int *array, int length) {
            int sum = 0;
            while (length > 0) {
                sum += *array;
                array++;
                length--;
           }
        }
        

        In rust, you can call that function safely by just wrapping it with a function that makes sure that length is always the size of array. Such as:

        fn rust_arraysum(array: Vec<i32>) -> i32 {
            unsafe{ arraysum(array.as_ptr(), array.len() as i32)}
        }
        

        Even though unsafe is used, it is perfectly safe to do so. And now we can call rust_arraysum without entering “unsafe mode”

        You could do similar wrappers if you want to write your embedded code. Where only a fraction of the code is potentially unsafe.

        And even in unsafe blocks, you don’t disable all of the rust checks.

        • NeatNit@discuss.tchncs.de
          link
          fedilink
          arrow-up
          4
          ·
          edit-2
          20 hours ago

          Thanks for this. I was paraphrasing (badly, it seems). The video actually says it better:

          To write code that lives in an embedded environment, it has to run in this mode in Rust called “no standard” (#![no_std]) and this mode called “no main” (#![no_main]). Basically you have no access to any of the core utilities in Rust, you have to write a lot of them yourself.

          He then explains how embedded code necessarily has global mutability which is “the antithesis” of Rust development.

          So yeah, you could make all of those wrappers, but at the end of the day you’ll end up with about the same amount of “unsafe” code as you would making the same thing in C++.

          Edit: but if what you said still applies, it does seem like Rust would watch your back somewhat better than C++ would in that it wouldn’t even compile unsafe operations outside of unsafe blocks, unlike C++ to the best of my knowledge where you kind of have to review the code yourself to make sure it only uses the appropriate wrappers.

      • Croquette@sh.itjust.works
        link
        fedilink
        arrow-up
        3
        ·
        1 day ago

        I am glad for your comment because I work with mcus and embedded solutions in C, so Rust, in that case, wouldn’t be neccesarily safer than C.

        I will have to look into it. I need to do 30h of training every two years, so I will learn Rust regardless, but I was thinking about eventually switching to Rust for embedded projects. Might just keep Rust as my scripting language because it is easier for me than Python

        • NeatNit@discuss.tchncs.de
          link
          fedilink
          arrow-up
          4
          ·
          20 hours ago

          It’s an interesting discussion. As someone who doesn’t actually deal with this and who literally never used Rust, I feel out of me depth. But it does sound like Rust has much better mechanisms to catch a programmer’s mistake. See my reply to the other guy.