Gamedev isn't some place of rainbows and unicorns that makes it a unique snowflake. I spent more than my fair share of time chasing down heap corruption, invalid iterators and all sorts of other fun issues.
If anything working on a console where the compile, cook, upload, play cycle can be long having something that removes a whole class of errors would have been great back then. I don't think anyone is saying Rust is a silver bullet but it certainly has aspects that are beneficial in certain contexts.
But I mainly take issue with the cockiness of my parent post. Rust is a reasonable evolution which, as you point out, eliminates one class of bugs. But my parent post took it for granted that things should be rewritten in it whenever possible, and that the gamedev community is ignorant of best practices.
The tech industry's demographic pyramid has a really wide base, which is possibly why it seems to build cults around new programming languages so much. Last time it was Ruby, and if we all listened to the equally self-assured Ruby crowd, everything would now be message passing up the wazoo.
Besides, syntax and complexity wise I think Rust is even worse than C++.
As a gamedev I am not interested in Rust. Zig, Jai and Odin seems much cooler/interesting.
I really hope this sort of strawmanning doesn’t become common here. In response to any reasonable discussion about Rust the response seems to be “you’re fine, but the other enthusiasts are so unreasonable”. Where are these enthusiasts? Why bring them up when you can just respond to the person you’re talking to?
It’s super annoying because even on irrelevant threads such haters will call people’s attention to these imagined enthusiasts. Like this comment from 6 days ago calling people jihadis if they like a language - https://news.ycombinator.com/item?id=32640154. Note that the jihadis didn’t exist on the thread, only in the commenter’s mind.
> I will say that I've never written a line of Rust in my life and certainly can't be described as representing the Rust community in any way.
If this is the best example out there then it does feel like GP was arguing against a strawman.
But even otherwise, please let’s acknowledge that in any large community there’s going to be a minority who are loud and rude. It doesn’t advance the conversation much to point it out. They don’t represent the whole community any more than the comment I linked to represents the whole HN community.
All I can say is that whenever I’ve seen such rudeness it’s moderated out pretty quick, whether here or elsewhere.
I don't think anyone here is saying that, at least in this thread the parent(and myself) were both careful to qualify there might be contexts that it could be useful in. If you see anyone saying that Rust solves every single problem then feel free to call them out for being full of shit :).
I'm not going to be giving my designers a Rust tutorial the same way we did with scripting Lua, you're still going to have a FFI somewhere which will require unsafe and a bit more care. However having had maintained pretty significant codebases in quite a few languages I will say that Rust code is more stable, crashes less and still runs in the same footprints as C++(C gets the codesize edge by having a much smaller stdlib and surface area). It's about knowing where your tools do well and where they have rough edges and a better tool is appropriate.
Having to switch between C, C++ and Rust codebases on a regular basis I think you're underselling the complexity of C++ and overselling how difficult Rust is. C++ has a huge surface area, you have to figure out what subset you want to use(exceptions: y/n?, RTTI: ditto, stdlib or custom containers, etc). Then you get into Rule-of-5, move semantics, template metaprogramming, undefined behaviors(don't use global constructors/destructors). I could easily list 20 years of various ways I've seen C++ explode in spectacular ways(volatile semantics anyone?).
If you want to use C, Zig, or C++ more power to ya. No one is forcing you to use Rust but for those of us who are interested in a language that isn't dragged along with decades of baggage Rust offers a compelling development story and largely delivers on the areas it aims to hit(accessible systems development, memory safety and first-class tooling in my experience).
Next question.
There is no substitute for engineering, if you care. So, engineer.
Avoid triggering exceptions too hard to recover from. That might involve work, but less work than fielding error codes would have been. There is no free lunch.
Some stuff that places Rust going into the same kind of complexity as C++.
Figuring out how to turn DAG algorithms into tree based ones, two macro systems, async infrastructure, Pin and PhantomData special fields, GAT (when they arrive).
Lets see how it looks like with 40 years of production code, on the other hand C++ is indeed reaching PL/I levels of complexity for those that care about ISO legalese.
The compiler’s error messages are fantastically helpful these days. Might be worth a tinker some rainy day, but understand being completely turned off of something as well.
https://play.rust-lang.org/?version=stable&mode=debug&editio...
If that code ever gets more use than that you expect, you can trivially find all the uses of “unwrap()”, and add the proper error handling. And yes there are quite a few places where things can go wrong.
But this explicit “signing for technical debt” when it relates to error handling is a really convenient productivity feature in practice.
A simple throwaway CLI for your own use is absolutely fine to use unwrap(), and you can fix it later on if it becomes a problem.
I can't go along with this at all
Jeezus.
As an outsider to both game dev and the general Rust ecosystem, but with a more than passing interest in the ECS data model (entirely apart from games!) and the prospect of using it safely with parallelism (entirely apart from memory safety concerns!), I found GP’s comment insightful and interesting. I find yours unnecessarily defensive.
I get that “in Rust” is a HN lightning rod, but maybe sometimes it’s okay for people to just appreciate someone’s personal project for the reasons they appreciate it, without it being an instant conflict?
Even in single player games, a game crashing and losing your progress sucks.
Rust’s non-borrow checker features help with other kinds of things. Rust isn’t only an ownership system.
It's turn based, so I don't need AAA game multi-threaded performance. It's single-player, so cheating doesn't really hurt anyone.
I use sanitizers to catch memory problems, but there have only been a few of those over the years. Maybe ECS just isn't that vulnerable to memory-safety problems?
The borrow checker prevents iterator invalidation problems, but most of my functions are read-only so there's not really a chance for those anyway, or many other single-threaded race conditions for that matter.
After this long using Rust, I'm noticing more and more that the borrow checker is imposing a lot of artificial complexity, when I compare it to my C++ version. We're often told that Rust is hard because the underlying problem is hard, but I've encountered many cases where that's not true, it really is just the borrow checker. And unfortunately, most of them are problems that Polonius won't fix.
Rust has a lot of great features (enums and cargo!) but I think one should think carefully about their domain and architecture before choosing a language, lest they pay too much cost for too little benefit.
Just my two cents!
I don't understand this, just because it's turn based it doesn't mean you can't squeeze more juice out of your CPU if you want to have all kinds of good graphics, fancy animations, fancy complex environments (lots of moving pieces, etc), physics simulation, etc.
Turn based is just one style of play but there's plenty of turn (or pseudo-turn) based games (like JRPGs) which struggle with platform limitations. One could even argue that games like Final Fantasy XIV are turn based.
To expand on this a bit. In games, objects generally fit into two categories:
1. Short-lived temporary objects, usually stack-allocated or arena-allocated, etc. e.g. a point vector, or matrix.
2. Long-lived objects with indeterminate lifetime. e.g. a character or item.
In the case of long-lived objects, there are various strategies you could use to make it safe e.g. using object IDs or custom smart pointers to refer to other objects that potentially might go missing instead of pointers which are bound to be corrupted.
Generally you want to register all of your long-lived objects in one central location that will handle memory management. Manual, reference counting or GC are all viable strategies depending on requirements.
I like Rust and would use it for games but mainly because of the package management.
Then you could just use a GC'd language. For example, you could use C# in Unity.
Out of curiosity, what are your favorite examples?
Personally, I've only struggled a bit with the borrow checker in a couples of cases: trying to have self/circular references when trying to model OOP, and when fiddling/interacting with some low level async code. Both were unnecessary in my case, and each situation was caused by a lack of understanding.
So you'd have something like:
enum List<T> {
Cons(T, Box<List<T>>),
Nil,
}
Since the list is now boxed up the borrow checker has a fixed sized object to put on the stack at compile time.Lack of self-referential types that are both safe and zero-cost is a legit limitation of Rust.
Do you use async closures? That's the only case where I felt the borrow checker is a bit behind. Also I haven't checked in a few months and I know there was some work ongoing.
That forced me to start organising the code in a different way which is less functional but easier to understand, so it's not crystal clear what's happening.
Rust is a great C and C++ replacement for low level stuff, I am still not convinced it is worthy versus those languages for distributed computing in terms of the productivity automatic memory management brings to the table.
> many interacting systems resulting in unpredictable behavior[0], buggy level geometry[1], or poorly scripted missions not accounting for all player behavior[2].
[0]: Rust borrowing system (you know exactly who is allowed to touch each ressource at a given point in time) is great at pushing you away from architecture with too much mutable interaction. That is a side effect of the system rather than its design purpose but, for my point of view, it is one of the main draw to write large projects in rust rather than C++.
[1]: probably not something Rust will help you with.
[2]: Rust type system (and overall coding conventions) is really good at building things such that it will only compile if you check for all cases or, at the very least, leave some explicitly unchecked cases.
These types of interactions exist at a layer where Rust can't help you. Even outside of gamedev, I would claim that most software bugs we run into every day are in this category: too high-level for the borrow checker. (Button not connected to anything. Scrollbar hidden, but the page is too long. Microservices that upgrade independently without API stability.)
> [2]: Rust type system (and overall coding conventions) is really good at building things such that it will only compile if you check for all cases or, at the very least, leave some explicitly unchecked cases.
I invite you to try to teach Rust's type system to level designers.
Other types of software projects also have their own complexity, budgets, changing requirements, and deadlines (admittedly not as major as a game release), but these things are managed differently.
Without telling all of gamedev that they're doing it all wrong, I'd like to say that perhaps there's another methodology that would also work. Especially that some games nowadays aren't just one-offs with a big-bang launch, but are maintained for years after initial release, which makes them look more like other software projects.
The kind of bugs that games mostly struggle with these days have nothing to do with the stuff Rust is targeting, like memory safety. They are “business logic” problems with many interacting systems resulting in unpredictable behavior, buggy level geometry, or poorly scripted missions not accounting for all player behavior. How exactly does Rust help with any of that?