I really think integrating something like Rust or D would be very interesting for Unreal Engine 4, and it seems I am far from being the only one.
Here are some quotes from the link above:
[]
It sounds like the problem was that UnrealScript was initially too simple for the applications it was pushed to, which led to more and more of the underlying system being exposed through the interop API.
[/]
[]
… C++ compile times will be a pain until a module system gets done.
[/]
[]
… D compiles much faster than C++, has limited C++ link compatibility (e.g. classes, but not templates), and overall has nicer syntax / language features than using C++ directly. Metaprogramming / compile-time introspection allow automatically serializing/deserializing data to allow updating data structures without restarting the engine.
[/]
[]
It will be interesting if any major game engines pop up using Rust as the core language, or even Go
[/]
[]
considering that Rust makes several classes of C++ bugs impossible at compile time, I’d be hard-pressed to imagine that a Rust version wouldn’t be less buggy.
[/]
[]
Rust’s type system eliminates the need to test for whole classes of bugs, because they are statically checked for at compile time.
[/]
[]
Rust emits LLVM IR, so that will make expanding to more platforms like iOS, PS4 and Enscripten much easier.
[/]
[]
What’s the appeal of Rust for gamedev?
bjz_ 129 days ago | link
- Fine grained control over allocation whilst maintaining memory safety (stack, heap, RC, GC, or roll your own)
- No null pointers (with an Option type that compiles down to a nullable pointer)
- Data race free concurrency
- Zero cost abstractions
- RAII and destructors
- No exceptions
- A modern, highly expressive type system
- Generics that throw type errors at the call site, not deep in a template expansion
- True immutability (not
const
)
- An excellent C FFI
- Compiles to native code
- You don’t pay for what you don’t use
- Safe by default, but you can circumvent the safety checks if you know what you are doing, and those places are clearly marked and easy to audit. Inline assembly is supported.
- Most safety is enforced statically, so you don’t pay for it at run time.
[/]
[]
I’ve discussed the issue of the “no decent programmer” fallacy in the past; yes, in theory if programmers were careful and alert, they could create flawless software, yet this never happens in practice because humans are prone to errors (i.e. not understanding a subtlety of the language or library, thinking that a validation is done at a different level of abstraction, failing to imagine what could be an error scenario and how it could occur, etc.). Languages like Rust offer the same capabilities as C or C++, while eliminating entire classes of bug sources.
[/]
[]
Although online security is more and more important in games these days, the real appeal of Rust in respect to game development is in providing an alternative to the ‘death by a thousand cuts’ that can plague large C++ projects.
I’ve posted a list of the things I consider the most relevant to game development: https://news.ycombinator.com/item?id=7587413 Any one or two of them alone wouldn’t really be a compelling enough reason to switch, but put together they form a very compelling value proposition.
[/]
[]
There already exists a subcommunity devoted to exploring Rust’s applicability to game development and computer graphics. The most active person in this department is probably Brendan Zabarauskas: http://voyager3.tumblr.com/post/82419271783/i-found-this-anc…
I also know of a few game development studios with R&D departments who have had an eye on Rust in the past…
[/]
In case you don’t know what Rust is, it’s a systems-programming language that compiles to native-code (using an LLVM-derived compiler).
It is developed by Mozilla for it’s next-gen web-browser (code-named “Servo”), but is an open-source project (dual-licensed MIT/Apache).
It aims is to be a viable substitution for C and C++ for performance-critical systems which require low-level access to hardware.
It is binary-compatible with C, and so has built-in interoperability with it (calling C library-members from Rust and vice-versa).
It provides a high-level abstraction that is very light-weight and “affordable” for performance.
It is much safer in terms of memory-management than most other languages - especially for concurrency (with “optional” garbage-collection).
It provides built-in primitives and language-support for concurrency that is similar to what languages like Go offers.
It draws inspiration from high-level languages like Python, Ruby and C# (as well as esoteric ones like Scala, Erlang and Haskell).
It is relatively-new (started being worked on in 2006), and is supposed to reach v-1.0 this year.
Here is a short video summarizing programming-languages and their trade-offs (and where Rust aims to be).
Here is a short video of an overview on Rust
Here is another short video showing small examples of the syntax and concepts.
Here is a somewhat longer video about Rust’s unique memory-management.
And lastly, here is a more exhaustive overview on Rust, it’s rationale/motivation, syntax and mechanics, with some C++ comparisons.
Here are some highlights from a very long thread about C++ vs Rust / Go:
[]
Consider that a lot of Python developers write most of their code in Python, then rewrite critical parts in C to speed it up. Python is not a speed demon, and that becomes particularly problematic with tight loops or heavy math—but writing entire applications in C is error-prone and tedious.
Rust won’t outright replace both of those, but it does offer a nice middle ground: it’s safe, it has some higher-level constructs, it does away with some boilerplate, it builds fairly easily, and it still compiles essentially to machine code.
[/]
[]
I’ve been under the impression that many people think that soon C and C++ will phase out and become obsolete(or that they have already done so), we go higher in abstractions, Python and Haskell are the future and computers are so fast that nobody has to care about optimizing their code. Then reality and post-PC era strikes back, battery life and software power-efficiency play higher role than ever…
My experience with Go and especially Rust is quite limited, but it would be really great if I could do my stuff(right now games and path tracing rendering, render times from 12 hours upwards) in either them instead of C++. I really like the ideas behind the languages and they fit my core domain just as well as C and C++ do.
[/]
And here is a about Garbage-Collection an game-development:
[]
Android games have been known to struggle with GC sometimes. However, garbage collection has gotten a LOT better on Android over the years. I wrote a small game in Android 1.1, back when GC pauses were anywhere from 100ms-250ms, and avoiding allocations was VERY important. Nowadays, most pauses are less than 5 ms, and the NDK is always available if you want to write native code and avoid GC altogether.
In general, the game industry seems to be moving towards a model where you have “engines” and “level packs.” The physics, graphics, etc. engines are developed by a small group of people in C or C++, and the level packs are in whatever scripty language you want.
[/]
And here is an article that tries to argue that C++11 will make new languages like Go and Rust redundant very soon - and the comments are pretty unanimously disagreeing with the writer.
Here is a from the article itself:
[]
“C++11 is out (has been for a while) and brings many things from Tr1 into the standard. Things like managed memory (shared_ptr) and lambdas and template meta programming (TMP) bring new paradigms to the beating heart of C++. So much so, I would argue, that C++11 makes some of the ‘new kids on the block’ (think Go and Rust) look pretty pointless.”
[/]
And here are some quotes from the comments:
[]
The reason we need new languages to replace C++ is because it is too easy to write C++ code that nobody else can understand. I have a Computer Science degree and 13 years commercial experience of C++ programming. You describe your example as “very trivial” and yet I find it baffling. I’d certainly understand a simple parser if it was written in C. I’d probably understand it if it were written in Java or C#, even though I have much less experience with those languages. I think the new C++ standard has made this problem worse. The Tiobe Index seems to agree with me. One thing C++ gets right is that it typically compiles to native code. I’d rather avoid Java and C# because they don’t. Therefore, I’m quite keen to see Go, Rust or D become widely used.
[/]
Memory-safety has been “bolted-on” as a library-feature in C++11, as opposed to a core-language features (mainly for reasons of backward-compatibility), so you don’t get compile-time help, and you can still soot yourself in the foot even with smart-pointers if you stray but-a-little from very strict usage-guidelines.
Here are some quotes from the first link, about C++11’s memory un-safety:
[]
here are a few things that modern C++ does nothing to protect against:
-
Iterator invalidation: if you destroy the contents of a container that you’re iterating over, undefined behavior. This has resulted in actual security bugs in Firefox.
std::vector v;
v.push_back(MyObject);
for (auto x : v) {
v.clear();
x->whatever(); // UB
}
-
“this” pointer invalidation: if you call a method on an object that is a unique_ptr or shared_ptr holds the only reference to, there are ways for the object to cause the smart pointer holding onto it to let go of it, causing the “this” pointer to go dangling. The simplest way is to have the object be stored in a global variable and to have the method overwrite the contents of that global. std::enable_shared_from_this can fix it, but only if you use it everywhere and use shared_ptr for all your objects that you plan to call methods on. (Nobody does this in practice because the overhead, both syntactic and at runtime, is far too high, and it doesn’t help for the STL classes, which don’t do this.)
class Foo;
unique_ptr<Foo> inst;
class Foo {
:
virtual void f();
void kaboom() {
inst = NULL;
f(); // UB if this == inst
}
};
-
Dangling references: similar to the above, but with arbitrary references. (To see this, refactor the code above into a static method with an explicit reference parameter: observe that the problem remains.) No references in C++ are actually safe.
-
Use after move: obvious. Undefined behavior.
-
Null pointer dereference: contrary to popular belief, null pointer dereference is undefined behavior, not a segfault. This means that the compiler is free to, for example, make you fall off the end of the function if you dereference a null pointer. In practice compilers don’t do this, because people dereference null pointers all the time, but they do assume that pointers that have been successfully dereferenced once cannot be null and remove those null checks. The latter optimization has caused at least one vulnerability in the Linux kernel.
Why does use after free matter? See the page here: Using freed memory | OWASP Foundation
In particular, note this: “If the newly allocated data chances to hold a class, in C++ for example, various function pointers may be scattered within the heap data. If one of these function pointers is overwritten with an address to valid shellcode, execution of arbitrary code can be achieved.” This happens a lot—not all use-after-free is exploitable, of course, but it happened often enough that all browsers had to start hacking in special allocators to try to reduce the possibility of exploitation of use-after-frees (search for “frame poisoning”).
[/]
[]
You can return out references and still get dangling pointers with const values. For example, you can return an iterator outside the scope it lives in and dereference that iterator for undefined behavior (use-after-free, possibly exploitable as above).
Besides, isn’t “C++ is memory safe if you don’t use mutation” (even if it were true—which it isn’t) an extremely uninteresting statement? That’s a very crippled subset of the language.
[/]
[]
> If you declared most of the mutable types const (and the use cases for a non-const unique_ptr are few) you can avoid most of these issues
Mutability in Rust is perfectly safe because of the static checks built into the type system – the compiler will catch you if you screw things up.
> you could never implement that without colossal backwards compatibility breakage
I cannot express how important immutability as default is. This prevents the issues that C++ has with folks forgetting to mark things as const. There is also lint that warns when locals are unnecessarily marked as mutable, which can catch some logic errors (I say that from experience).
Also note that I said ‘immutability’ not ‘const’. Immutability is a far stronger invariant than const, and therefore is much safer. It could also lead to better compile-time optimisations in the future. I’m sure you know this, but just in case:
- const: you can’t mutate it, but others possibly can - immutable: nobody can mutate it
[/]
Another major problematic-area about C++ is how small it’s standard-library is in comparison with languages that are not designed-by-comity.
You got so many different options for simple tasks like threads, sockets, XML/ handling etc. that don’t inter-operate well, and have varying platform-support.
Then you got “some” cross-platform library-packages like Qt and Boost that have their own issues and non-standard style/behavior.
There is a very glaring lack of canonical go-to solutions that are standardized for even basic/rudimentary stuff, and that is a major problem that has existed for years.
Another problem with C++ is incompatible-compilers - this is horrible and largely un-fixable at this point - it is a product of historical-political/commercial factors, that sometimes caused different vendors to deliberately do the opposite things when implementing their compilers compared to what their competitors where doing, specifically for no other purpose then instilling incompatibility. Each vendor thought to lock-down the users of his compiler to his platform, as a means to dominate the market. This is horrid and means you have to re-compile code that is “supposed to have been cross-platform-portable” but isn’t, even when it’s not even referencing any platform-specific code whatsoever, only because some compilers implement things differently, either internally in corner-cases, or on the surface with incompatible pre-processor directives.
And so the promise of “cross-platform compatibility” is largely marketing-■■■■■■■■…
In a few weeks “CppCon 2014” is going to happen (the successor to the “Going-Native” conferences), and video-recordings of it will follow - we’ll see what they have to say then…