News for hackers. Stuff that matters.
Re:Leaving Rust gamedev after 3 years by remram on Friday April 26, 2024 @09:43PM (#40176341)
Sorry I got lost in that sentence. What is Rust's model?
Re:Leaving Rust gamedev after 3 years by hot_gril on Friday April 26, 2024 @10:30PM (#40176605)
Rust has traits on structs instead of using inheritance. Aka composition.
Re:Leaving Rust gamedev after 3 years by zozbot234 on Saturday April 27, 2024 @03:12AM (#40177955)
You can also have structs be generic over some "tag" type, which when combined with trait definitions gets you quite close to implementation inheritance as seen in C++ and elsewhere. It's just less common because usually composition is all that's required.
Re:Leaving Rust gamedev after 3 years by psychoslave on Saturday April 27, 2024 @06:14AM (#40178803)
Even PHP as traits by now. Languages tend to incorporate others Languages successful features. There is of course feature inflation risk of course. There are Languages that take as a goal to avoid that inflation, such as Zig, or that arrives there as a byproduct of being very focused in a specific use case like AWK.
Re:Leaving Rust gamedev after 3 years by remram on Saturday April 27, 2024 @11:52AM (#40180896)
But that... wasn't in your comment at all...

If I say "I don't care about safety, I care about expressiveness. Which is Rust's model"... "which" has to refer to one of the other things I just mentioned (safety or expressiveness) not some other concept.

Re:Leaving Rust gamedev after 3 years by Toutouxc on Saturday April 27, 2024 @03:40PM (#40182796)
AFAIK composition, in the traditional sense, means that you put your objects/concepts together from different smaller objects or concepts. Composition would be to have a struct Car that uses another struct called Engine to handle its driving needs. A car “has a” engine. A trait that implements the “this thing has an engine” behavior isn’t composition, it’s actually much closer to [multiple] inheritance (a car “is a” motorized vehicle).
Re:Leaving Rust gamedev after 3 years by zozbot234 on Saturday April 27, 2024 @05:53PM (#40183928)
Traits do implement interface inheritance, but that doesn't have the same general drawbacks as implementation inheritance (such as the well-known "fragile base class" problem).
Re:Leaving Rust gamedev after 3 years by hot_gril on Monday April 29, 2024 @12:34PM (#40200594)
I don't know the terminology. I just know that Rust does whatever the alternative is to the Java way with inheritance. You don't get stuck with the classic classification problem.