4 ms·
The basic problem with C++ is that it has has hiding without safety. C has neither, and most newer languages have both. Attempts to add safety to C++ via templa
by Animats 5y ago
The basic problem with C++ is that it has has hiding without safety. C has neither, and most newer languages have both. Attempts to add safety to C++ via templates always seem to leak raw pointers, since many APIs never converted to C++. It's significant that there isn't a C++ Linux kernel API, where you use C++ strings for everything and get rid of the null-terminated stuff.
You see this in the original poster's example. He's doing C-type I/O in C++. Of course it doesn't work cleanly.
It's frustrating. C++ is object-oriented. The cool kids don't like that. So, Rust isn't object-oriented; it uses traits and generics. Those are different enough that there is no one-to-one way to convert modern C++ into safe Rust. It takes a redesign.
So we're kind of stuck.
If you're familiar with game engines, consider what it would take to convert Unreal Engine to Rust.
- dathinab 5y agoI would say many (not all) game engines could probably be converted, by finding common pattern in usage of inheritance and mapping it to rust patterns. EDIT: Through automatizing this, or making C++ to rust bindings for it would be hard. I mean creating inheritance graphs for entities is as far as I know already seen as an anti pattern since a while. Things like ECM are nicely re-presentable in rust. Many patterns of inheritance for code re-use tent to also not be too hard to represent in rust. But I would argue that even if rust had inheritance engines like Unreal Engine would not be ported, at least not until they do a major rewrite anyway. Because of it being a lot of work with not too much intermediate gains.
- biesnecker 5y agoThere's a pretty wide gap, though, between "nicely representable in rust" and "mechanically translatable from the C++ implementation" that mostly requires human effort to span.
- dathinab 5y agoYes, though even if rust had inheritance I don't think you would have a machine translatable mapping good enough to port a game engine. Generally for any language which in design isn't "somewhat close to C++" I don't think this would work.
- Animats 5y agoRight. C++ to Rust is a big jump. C++ to C# or Java or D might be automatable. At least the object model is roughly compatible.
- Shadonototra 5y agorust is not good for game dev compilation time is even worse than c++ there are hidden allocations EVERYWHERE that you can't even control stop trying to push that narrative, it makes rust look bad rust is nice if you target things like drivers, anything else it's bad the other day i read people who thought rust could replace javascript just take a nap and move on, you are delusional
- bsder 5y ago> compilation time is even worse than c++ That's highly dependent. C++ is pretty bad and I've seen quite a few codebases where the C++ is way worse than the equivalent of Rust. > there are hidden allocations EVERYWHERE that you can't even control That's simply not true. It's also a highly ironic statement given the tendency of C++ to have all manner of allocations all over the place (example--look at how many people implement their own String instead of using the STL one). You can control the allocations in Rust, but you do have to do so explicitly. Agreed, this is more like C than C++. > stop trying to push that narrative, it makes rust look bad Yeah, I kind of agree with this in the game space. There are a LOT of things that Rust does poorly within the gaming space. Being able to efficiently transmute between equivalent types of memory (array of 4 bytes, an RGBA packed struct, and a uint32_t, for example) without losing performance is something Rust is really bad at. Packed structs are poor. There really isn't a good set of idioms for GUIs. ECS seems like a bit of a hack to get around the inability to transmute types efficiently. etc. Oddly, one space that Rust is gaining traction in the gaming space is the network communication layer. People are simply tired of debugging buffer overruns and have decided that they'd much rather have something different. And, since Rust can compile down to a library, it can be linked into the rest of your game and not interfere with your pipeline. > just take a nap and move on, you are delusional Hey! You don't need to be delusional to take a nap. You can like naps just fine without being delusional.
- pjmlp 5y agoRust/WinRT has a ticket where currently it takes 10x times longer to compiler than C++/WinRT.
- b20000 5y agoC++ is a multi paradigm language, it is not “object oriented” necessarily. also, there is nothing wrong with C++. it’s C with additional language constructs and the STL. use as much or as little as you want of it. also, there is no such thing as leaking a pointer. you can leak a piece of memory. at the end of the day you need to understand operating systems and how memory management, CPUs and instruction sets work and lots of other low level stuff to build software using C or C++. Rust might temprarily help with some challenges or shield off certain otherwise advanced challenges but in the end there is no way around learning how the machine you write software for works. if you don’t want to deal with that, go build websites.
- throwaway5486nv 5y agoWhat other paradigms are popular with C++? Never came across anything else other than object programming.
- Jtsummers 5y agoGeneric, functional (with the introduction of lambdas and closures, in particular), procedural. Some of the features may use the class system under the hood, but with a very shallow hierarchy it's more akin to a trait/interface system if you drop the deep class hierarchy style that was more prevalent in the 90s.
- throwaway5486nv 5y agoAre there any popular open source projects that has adopted non object oriented programming style?
- Jtsummers 5y agoI'd just look at the C++ Standard Library which relies far more on the procedural, generic, and functional styles than OO. Using it, you often (IME) end up writing code more along the trait/interface style than the OO-hierarchy style that was popular in the 90s. But I have no idea about open source C++ projects, I don't follow them and mostly don't care. I've really only used C++ at work where 99% of the code seems to be procedural, not OO. The closest is that they have "classes" which are barely more than plain data objects ("smart" structs), if they have methods it's to enforce data invariants and almost nothing else.