Announcement

Collapse
No announcement yet.

Rust for UE ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #31
    Originally posted by EvilCleric View Post
    C++98, C++03, C++11, C++14, C++17, C++20, C++23, C++26, ...
    C++ is constantly evolving, and the best of all: backwards compability.

    Someone once said:



    Why Rust will never replace C++? Because Rust doesn't provide us with a slow and adaptive transition, like C -> C++.

    And so, Rust will have the same fate as every other pretender.
    Rust does provide an adaptive transition. Rust is very compatible with C. It's just C++ that may need extra work (it always does, doesn't it?). And not everything is written in C++.

    Many crucial MS APIs like DirectX are under the COM interface that are language neutral. DirectX is owned by MS.

    Yeah, it's currently uncertain who is going to make Rust bindings for DirectX, whether it be MS or the Rust community again, but the COM Rust bindings generator is currently made by MS. We will know once VS 2021 is out in preview, and MS made their final choice to embrace Rust. With a giant like MS behind Rust, Rust won't go back into its corner that fast if at all. And of course that's important for those who already chose Rust already, too.


    "We are the Rust language. Lower your shields and surrender your code. We will add your jobs and technological distinctiveness to our own. Your culture will adapt to service us. Resistance is futile!"
    -- At Microsoft Build 2021


    Jokes aside, if Rust can't dethrone C/C++, then no language ever will. Which is fine if it manages to evolve fast enough, but the race is on.

    I'm not aware that there ever was a bigger threat to C/C++ than the Rust language. One subjective view tells me that there are a large amount of Rust presentations I came across. The more actual fact that gives that away is its 4 years long streak in being the most loved language on Github and the large code base on Crate.io. Add a thousand Rust jobs at MS with DirectX bindings and the Rust written game engines will be coming ringing in. Yes, there are DX bindings in the Winapi Crate already, but they are incomplete and handwritten.

    I can't tell how many companies are behind D, Limbo, Vala etc, but Rust got many of production grade users.

    Comment


      #32
      Originally posted by EvilCleric View Post
      Why Rust will never replace C++? Because Rust doesn't provide us with a slow and adaptive transition, like C -> C++.
      And so, Rust will have the same fate as every other pretender.
      There has to be a more security-focused language shift at some point imo.
      This may not affect non-mission-critical applications like game engines etc.

      But...

      The godfather behind C++ still sees some weaknesses / room to improve.
      Some of it is about simplifying programming approaches (last paragraph).
      Complexity is the enemy of simplicity & absence of simplicity leaves holes.

      Comment


        #33
        Originally posted by Raildex_ View Post
        Stability doesnt come from a language.
        It actually may to a large extend.

        It's just that normally a language may not be so obviously superior to another. It may be up to subjective debate whether specific features are better or worse. And all you get is a syntax war in the forums defending their religion or reasonability though, trying to avoid having to learn yet another language.

        However... we are not comparing C# vs F# here. We are comparing C/C++ with Rust, both are system languages a.k.a. native code languages, but one of them isn't a safe language.
        We are not comparing the lack of a semicolon in F# vs the bracket kingdom of C#. And that's not giving enough credit to what F# brings to the table. Just my opinion, anyways.

        But we talk about: Unsafe threads, seg faults, null exceptions, dangling pointers, memory leaks, etc. That kind of stuff of nightmares that is more than just syntax inconveniences, and can be avoided fully just by switching languages.

        Regarding stability Rust certainly adds a massive ton to the code. With Rust you get a measurable increase in stability. That's why MS is willing to invest a ton of money and bring Rust to their ecosystem instead of hiring better C/C++ programmers that could have avoided their "70%" of security issues. That's not a trivial task for a company as big as MS, it ain't done out of shear fun. And the security issues are driven by the safety issues of C/C++, it's an unsafe language. It's that simple in the end.

        It's like arguing that native code is faster than managed code, uhm, duh? Rust is faster than F# in general, and especially in real time applications.
        Yes, Rust is a safe language. No, C/C++ isn't a safe language. So Rust will deliver stability out of the box while C/C++ won't.

        It's just companies like MS who got security issues to deal with that can get into the millions/billions when exploited by a hacker. That are the first to point out that C/C++ lacks safety and needs to improve or risk getting replaced by another language that is safe. Like Rust.

        But to be clear. The security issues are driven by the lack of safe code, so how C/C++ handles, or rather doesn't handle its pointers. What ever crimes C/C++ may have committed with its syntax, or bloat, the biggest issue is safety even for non security critical applications. Getting a seg fault, undefined behaviors, memory leaks, etc, ain't "stability" it's a waste of productive time because you are using an inferior language.

        Like I said before. It would have been obviously way more ideal for C/C++ to evolve instead. But it seems that it just does so too slowly. Otherwise MS would have waited for a better version instead of considering to ditch C/C++ all together in favor of Rust and spending a ton of money and effort on reforming their giant empire.

        Comment


          #34
          First of all there is no C/C++ language. Quick example: VLA is legal in C, but illegal in C++. This is the main reason why C++ is being hatred. Because it is taught as "C with classes."
          https://en.wikipedia.org/wiki/Compat..._C_and_C%2B%2B
          I highly recommend this video:

          In modern C++ we have smart pointers and RAII. Using raw pointers (with raw new/delete) is antipattern. UE4 use raw pointers heavily.
          In modern C++ we avoid macros because we have type safe constexpr and templates. UE4 uses macros heavily, UObject cannot be templated.
          In modern C++ we prefer composition over inheritance and generic programming. UE4 is "inheritance-everywhere"
          In modern C++ raw loops can be replaced with range-for or even better with algorithms/std::ranges.
          C++20 introduce modules, so headers can gone.

          OOP generally isnt bad, its simply misunderstood. Like Alan Key, considered as a father of OOP says:
          “I’m sorry that I long ago coined the term “objects” for this topic because it gets many people to focus on the lesser idea. The big idea is messaging.”

          As you can see, these are not problems of the language itself, but flaws of UE4 codebase. Introducing a new language will not make them magically disappear.

          Comment


            #35
            Originally posted by Emaer View Post
            First of all there is no C/C++ language. Quick example: VLA is legal in C, but illegal in C++. This is the main reason why C++ is being hatred. Because it is taught as "C with classes."
            https://en.wikipedia.org/wiki/Compat..._C_and_C%2B%2B
            I highly recommend this video:

            In modern C++ we have smart pointers and RAII. Using raw pointers (with raw new/delete) is antipattern. UE4 use raw pointers heavily.
            In modern C++ we avoid macros because we have type safe constexpr and templates. UE4 uses macros heavily, UObject cannot be templated.
            In modern C++ we prefer composition over inheritance and generic programming. UE4 is "inheritance-everywhere"
            In modern C++ raw loops can be replaced with range-for or even better with algorithms/std::ranges.
            C++20 introduce modules, so headers can gone.

            OOP generally isnt bad, its simply misunderstood. Like Alan Key, considered as a father of OOP says:
            “I’m sorry that I long ago coined the term “objects” for this topic because it gets many people to focus on the lesser idea. The big idea is messaging.”

            As you can see, these are not problems of the language itself, but flaws of UE4 codebase. Introducing a new language will not make them magically disappear.
            So, to what extend is modern C++ as safe language? Rust is 100% safe. Well, maybe make it a 99%...

            And for the record, since you mentioned how UE4 is written in the first place. WinRT is also written in a object oriented way. It got Win32, so C in it, too. However, unlike C++/WinRT, Rust/WinRT is still 100% safe according to MS no matter what the actual underneath code is. The same with C# for Unity. Unity isn't written in C#, but C++. Any gameplay code written still will fully or at least mostly draw from the advantages of the language that it was written in.

            Any Rust game logic will be safe by default unless written in unsafe code blocks provided that the bindings are also safe and not raw bindings going directly into C++ code via C.

            Comment


              #36
              When I was messing around Rustlang I noticed the compiler was considerably slower than c++ compiler.
              I don't know how it is today, but there I was already thinking "-imagine this thing compiling a big project like a Unreal game, would be pain".

              If crates are more malleable now would be cool to see some experiments, but my experience those days wasn't great.
              Btw, c++ is already too slow to compile Unreal projects.. Rust could be worse.
              | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

              Comment


                #37
                Rust compilers are slow for the same reason that C++ compilers are slow when using tons of templates. Type inference is a guided combinatorial graph search, which just takes time.
                (Other "beneficiaries" of this include languages like Swift, and Haskell.)
                You can write Rust that compiles faster, by making the types simpler, just like you can make C++ that compiles faster by making it look more like C. (FWIW, Unreal Engine C++ looks more like C than like modern C++, and this is probably good for the needs of the engine.)

                Comment


                  #38
                  Originally posted by BrUnO XaVIeR View Post
                  When I was messing around Rustlang I noticed the compiler was considerably slower than c++ compiler.
                  I don't know how it is today, but there I was already thinking "-imagine this thing compiling a big project like a Unreal game, would be pain".

                  If crates are more malleable now would be cool to see some experiments, but my experience those days wasn't great.
                  Btw, c++ is already too slow to compile Unreal projects.. Rust could be worse.
                  I'm afraid I'm not well informed about the slow compile time issues, I only heard of them. I have a Ryzen 7 with 16 threads so I'm not the first who will feel this.

                  For what it's worth. Rust is only 9 years old. While C/C++ are almost half a century old. C is 48, C++ is 35. Even F# is older than Rust with its 15 years. So, there is a ton of optimization that when into C/C++ compilers and run times. Rust can only get better at this point.

                  And depending how you use C++, the compile times also can get worse because of how modern languages aim to do more during their compile times in general these days.

                  I noticed it first with F# that the designers talked about wanting a very static and strong typed language because of the compile time advantages that they can gain from it. Like less bug prone code that shows its self only during run time. That's the reason why there is no Null type a.k.a. the Billion Dollar mistake in Rust/F# for starters.

                  Comment


                    #39
                    Originally posted by NickelCoating View Post
                    For what it's worth. Rust is only 9 years old.
                    Only 9 years and it's already rusty.
                    "I have harnessed the shadows that stride from world to world to sow death and madness."

                    Comment


                      #40
                      Originally posted by NickelCoating View Post
                      For what it's worth. Rust is only 9 years old. While C/C++ are almost half a century old. C is 48, C++ is 35. Even F# is older than Rust with its 15 years. So, there is a ton of optimization that when into C/C++ compilers and run times. Rust can only get better at this point.
                      Actually, there's also a lot of things cannot be optimized/changed in the language to keep it compatible with the past code. Actually I feel there are a lot of optimizations in the compiler to make a program run faster or safer, not necessarily faster compilation times. But this irrelevant to me, with modern CPU it's possible to compile UE4 (nearly 3 million lines of code) in 15 minutes or less. What was most annoying: UHT running on a single thread and often taking a minute to complete its task. Thank God, it's fixed

                      C++ 20 modules are more interesting to me than compilation times

                      Comment


                        #41
                        Originally posted by NickelCoating View Post
                        So, to what extend is modern C++ as safe language? Rust is 100% safe. Well, maybe make it a 99%...
                        I only referred to the most frequently mentioned problems:
                        Originally posted by NickelCoating View Post
                        But we talk about: Unsafe threads, seg faults, null exceptions, dangling pointers, memory leaks, etc. That kind of stuff of nightmares that is more than just syntax inconveniences, and can be avoided fully just by switching languages.
                        What are these problems arising from? Because you have a multitude of interconnected classes and it's simply hard to remember who owns what and how long they exists. Raw pointers dont provide any information about ownership, even worse if the ownership is blurred, because it is managed by GC "from the back seat".
                        Seg faults/dangling pointers/mem leaks are not a problem if you use smart pointers, because you clearly see which resource is shared/unique or can be null(weak).

                        I am not against Rust at all, but I do not see any positives of introducing it, if there is still a mess "under the hood" and any work going beyond the "mainstream" framework forces me to mentally go back to the '90s.

                        Comment


                          #42
                          Originally posted by Emaer View Post

                          I only referred to the most frequently mentioned problems:


                          What are these problems arising from? Because you have a multitude of interconnected classes and it's simply hard to remember who owns what and how long they exists. Raw pointers dont provide any information about ownership, even worse if the ownership is blurred, because it is managed by GC "from the back seat".
                          Seg faults/dangling pointers/mem leaks are not a problem if you use smart pointers, because you clearly see which resource is shared/unique or can be null(weak).
                          How many pointers does C++ even have now? There is a normal/raw, shared, auto, weak, and smart pointer? Why is it that for anything you do in C++ you need to pull a 1000 pages sized book out of a shelve? I'm afraid that's the part where C++ isn't only toughed badly, but is just badly designed in its own very nature.

                          Rust got only one pointer and it's a safe language. C++ still isn't exactly a "safe" language. Yeah, I know, you can also make a game with assembly language. And you can make it "safe", too. And you maybe don't need a 1000 pages sized book, but 1000 years instead. Still I'm not going to battle with a dull sword unless I have no other choice. Chop, chop, now. Not later.

                          So, C++ ain't a productivity king either because of this. While Rust is as fast as C++ while being virtually as productive as C#. Though, for the record, Rust always feels at least a half a notch more low level than C# since Rust always uses pointers and never a GC. You don't do dereferencing in C# really.

                          Well, bottom line, if C++ won't get any simpler for doing the same, or actually even less, than at some point when MS and other companies created enough jobs, C++ may get its death sentence. Because schools won't put up with a language that's hard/confusing to teach either, nor new programmers.

                          Although it's only 9 years old. Rust is having an effect on other languages. Like its editions system. That said, I think C++ got modules now only because of Rust.

                          Originally posted by EvilCleric View Post

                          Only 9 years and it's already rusty.
                          You get used to the name. But I would have called it Mozilla. Yes, Rust is made by Mozilla.

                          Now imagine a terrified Japanese uttering(maybe Ken Watanabe from the 2014 Godzilla movie): To restore balance, Mozilla must face Cong++. Let them fight!

                          Comment


                            #43
                            Originally posted by NickelCoating View Post
                            How many pointers does C++ even have now? There is a normal/raw, shared, auto, weak, and smart pointer? Why is it that for anything you do in C++ you need to pull a 1000 pages sized book out of a shelve?
                            IMHO it would be a more productive conversation if you would exaggerate so much. You don't a 1000 pages book to write a game with Unreal C++.
                            There's a raw pointer in C++ and Unreal brings its smart pointer - in 4 flavors, all quite similar in usage. Usually, weak pointer needed in the gameplay logic. Using it's straightforward.

                            Rust is quite an interesting language and I would try at home just for sake trying something new if time would allow.

                            Although I keep hearing from other programmers that Rust is more focused on safety than performance, ensuring ownership of objects. It seems tailored for web-related things, but still didn't any convincing explanation why need it so much for video games? I mean, UE4 provides what I need and it's good enough. It could be a bit different to talk about writing a new engine from scratch and I'm curious about Rust-based engines

                            What's wrong with GC? I mean, it just works for me in UE4. Why I should need another language without it? Why isn't just another fad? It's not sarcasm, I'm honestly curious.
                            People would have to learn both Rust and C++ - since latter it's not going anywhere, the engine wouldn't be magically rewritten to Rust. It's exactly the same issue with every language which wouldn't be a scripting language designed to be something between Unreal C++ and blueprints.

                            Comment


                              #44
                              Originally posted by Moth Doctor View Post
                              Although I keep hearing from other programmers that Rust is more focused on safety than performance, ensuring ownership of objects. It seems tailored for web-related things, but still didn't any convincing explanation why need it so much for video games? I mean, UE4 provides what I need and it's good enough. It could be a bit different to talk about writing a new engine from scratch and I'm curious about Rust-based engines
                              The Rust language itself ain't tailored really for any kind of specific domain, it's a system language. However, it had to start somewhere, and it's Mozilla who makes Rust, so since they are already in the web field, they started there by rewriting internals for the Fire Fox browser in Rust. Some ditched their old languages and rewrote in Rust to gain massive performance boosts and smaller memory foot prints.

                              And regarding performance, it's only safe rust that may be slower than C++. You can write anytime anywhere inside safe Rust code so called unsafe blocks/functions for performance critical parts if needed. It's very hard to pin point the performance loss. it really depends on the performance intensive code, but the worst number I saw was 15% in safe Rust.

                              A small price to pay for a clean, maintainable, and very stable code base that allows the programmers to be productive. Time is money these days more than ever. That's the edge you get with Rust over C++ as Rust gives move than just the language itself. It's the Cargo/Crate system, the documentation, and code formatting system. It's this kind of consistency, wholeness, that make companies eventually choose Rust in addition to it safe and clean code. Plus, plus(see what I did here?), it's simpler to teach to new employees.

                              Oh, and 15% compared to a 100FPS C++ code, doesn't translate to 15FPS loss in Rust. It's less than 15FPS. Hence a small price to pay. And safe Rust is always faster than managed code C#/F# in general.
                              Originally posted by Moth Doctor View Post
                              What's wrong with GC? I mean, it just works for me in UE4. Why I should need another language without it? Why isn't just another fad? It's not sarcasm, I'm honestly curious.
                              People would have to learn both Rust and C++ - since latter it's not going anywhere, the engine wouldn't be magically rewritten to Rust. It's exactly the same issue with every language which wouldn't be a scripting language designed to be something between Unreal C++ and blueprints.
                              Yeah, I know, it depends on your project. But, yeah, managed code has come a long way and got a ton of performance improvements. There are C# written game engines, Space Engineer is one of them, it's not that bad. But heck, I got a Ryzen 7 3700x 16 threads, and the GC hiccups are just there. Only Unity games can get away with it, because it's only the game logic that is written in C#, and Unity/UE games tend to be simple. Seems Cities Skyline had to use native code even with Unity.

                              Anyways, Rust isn't meant to compete with C/C++, it is mean to replace it. However, it can compete with C# in my opinion. C#, or any managed code in general, looses FPS even with the boundary transition between managed/native alone. Epic Games pointed that out, and they are not happy about that. It's sub optimal obviously. Yet, Rust is to my opinion only half a notch "harder" than C#. Yet virtually comes with the performance of C/C++.

                              MS made C#, and it's part of VS, Eventually MS will add Rust to VS, too. That's the perfect ground for competing. MS is already working Rust/WinRT just like it does on C#/WinRT. Except, Rust is still not Dot Net based, which may be off putting to some, but in general that's better because even with cross platform .Net you got the closed platform smell of MS all over it. Unlike with Rust that is cross platform just like C/C++ and many of its APIs.

                              Originally posted by Moth Doctor View Post
                              People would have to learn both Rust and C++ - since latter it's not going anywhere,
                              For game logic only, it's more like learning Rust and C#, not C++. If UE supported Rust it still would support C++ of course. And Unity devs absolutely wouldn't care about learning C++.

                              With game logic you actually can get away with not learning C/C++ much easier these days, than with say, trying to make a game engine.

                              Trying to make the UE community except Rust is a notch likelier than Unity devs. Because Unity already got C#. Yes, many actually want F# because C# is messy to work with, but anyways...

                              Originally posted by Moth Doctor View Post
                              It could be a bit different to talk about writing a new engine from scratch and I'm curious about Rust-based engines
                              It depends on the type of engine, but for 3D it's not pretty. Rust will suffer like Linux if MS doesn't help out with APIs. But Rust/WinRT is on the way and is made by MS itself.

                              Originally posted by Moth Doctor View Post
                              the engine wouldn't be magically rewritten to Rust.
                              Don't hold your breath on that present moment fact. There are translation tools already for some languages. There could be a translator in the future for Rust. This may largely erase C/C++'s ability to hide behind its established domain any longer to maker infinite excuses for being **** as a language itself.

                              I prefer Rust over C/C++ obviously. But I wouldn't want to be a Rust language dev. I'm constantly wondering why Rust lang devs even really try. Because although C/C++ may evolve very slowly, at some point when Rust hunts it down, and it does already, and then C/C++ would evolve faster trying to defend its domain. And it does. So, maybe it's those translators that is Mozilla's Atomic Breath to beat Cong++.

                              Adding Rust now, can start a transition to an UE version that is fully written in Rust by letting dev learning and getting used to it now.

                              Comment


                                #45
                                Originally posted by NickelCoating View Post
                                The Rust language itself ain't tailored really for any kind of specific domain, it's a system language. However, it had to start somewhere, and it's Mozilla who makes Rust, so since they are already in the web field, they started there by rewriting internals for the Fire Fox browser in Rust. Some ditched their old languages and rewrote in Rust to gain massive performance boosts and smaller memory foot prints.
                                If Rust has it role in Firefox "reboot" some time age and Firefox cut memory usage to 1/3 less than Chrome... it gains some respect now

                                Originally posted by NickelCoating View Post
                                Oh, and 15% compared to a 100FPS C++ code, doesn't translate to 15FPS loss in Rust. It's less than 15FPS. Hence a small price to pay. And safe Rust is always faster than managed code C#/F# in general.
                                Well, 15% lost on the language itself and even just 10 fps lost? It's huge and unacceptable.
                                Maybe if it would allow for some multithreading code written easier to get some performance back, then it could be interesting. With next-gen consoles better utilization of high CPU core count would be very appreciated.

                                Originally posted by NickelCoating View Post
                                Yeah, I know, it depends on your project. But, yeah, managed code has come a long way and got a ton of performance improvements. There are C# written game engines, Space Engineer is one of them, it's not that bad. But heck, I got a Ryzen 7 3700x 16 threads, and the GC hiccups are just there. Only Unity games can get away with it, because it's only the game logic that is written in C#, and Unity/UE games tend to be simple. Seems Cities Skyline had to use native code even with Unity.

                                Anyways, Rust isn't meant to compete with C/C++, it is mean to replace it. However, it can compete with C# in my opinion. C#, or any managed code in general, looses FPS even with the boundary transition between managed/native alone. Epic Games pointed that out, and they are not happy about that. It's sub optimal obviously. Yet, Rust is to my opinion only half a notch "harder" than C#. Yet virtually comes with the performance of C/C++.

                                For game logic only, it's more like learning Rust and C#, not C++. If UE supported Rust it still would support C++ of course. And Unity devs absolutely wouldn't care about learning C++.
                                Great point!
                                Although even a simple Unity game could suffer from bad performance, no way to manage memory. I heart that Unity being entirely rewritten to ECS it's more about optimizing memory management with C# projects (and large chunks of the engine itself) than solving issues with OOP specifically.

                                In this light, Rust actually sounds tasty in comparison to C# which simply "costs" too much for its simplicity

                                Comment

                                Working...
                                X