News for hackers. Stuff that matters.
Re:Async Rust Is A Bad Language by 0xDEF on Friday September 08, 2023 @03:17PM (#37438119)

    "I've learned to live without objects, but the trait system is somewhat convoluted. There's one area of asset processing that really wants to be object oriented, and I have more duplicate code there than I like. I could probably rewrite it to use traits more, but it would take some bashing to make it fit the trait paradigm."
Can you expand on this? I come from the C# world and the Rust trait system feels expressive enough to implement the good parts of OOP.
Re:Async Rust Is A Bad Language by bombela on Friday September 08, 2023 @03:27PM (#37438247)
I understand this not as objects are missing, after all, struct with methods and traits are objects aren't they? But more like the lack of hierarchical inheritance, that is most often used in OOP to conveniently share common code with added specialization. Override only the methods you want. You can do it with Traits of course, but it's much more verbose. You can technically use the defer trait to simulate a sort of method inheritance, but it is frowned upon as it should be reserved for smart-pointer like objects (so the doc says).
Re:Async Rust Is A Bad Language by Animats on Friday September 08, 2023 @03:57PM (#37438626)
That's about what I was going to say. Traits have no data of their own. If you need that, you have to construct it, with a data object in each trait instance and access functions for it. It turns the notion of inheritance inside out. Awkward enough that it's only done if absolutely necessary.
Re:Async Rust Is A Bad Language by radicalbyte on Friday September 08, 2023 @04:53PM (#37439271)
I'm from the C# world and am working through learning Rust... in C# we've largely moved away from using inheritance. Not sure that it's a good thing but "best practise" results in serialisation being implemented differently (serialisers which use attributes, or for more advanced teams serialisation wired in at compile time targeted by attributes - advantage here being that the state doesn't have to be public).
Re:Async Rust Is A Bad Language by wvenable on Friday September 08, 2023 @08:36PM (#37441025)
I still use inheritance in C# although it is only used for is-a relationships and those aren't that common. But when you need it for that, it's usually pretty important.

I also think it's much more common to see it in library / framework code and not in application code.

Re:Async Rust Is A Bad Language by vacuity on Friday September 08, 2023 @09:11PM (#37441213)
UI in Rust without inheritance is tricky. There's still no great UI framework written in Rust yet, though not for lack of trying! I'm interested to see how Bevy's UI turns out. They're currently exploring the design space and requirements for production-grade UI, actually.
Re:Async Rust Is A Bad Language by twodave on Saturday September 09, 2023 @08:32AM (#37444572)
Wouldn’t something akin to swift UI work well in this situation? I can understand that not having a “component” class to inherit would make building custom components difficult, but if most layout and skinning can be accomplish via functions then you can sidestep the issue for most cases I think…
Re:Async Rust Is A Bad Language by vacuity on Saturday September 09, 2023 @11:04AM (#37446212)
I think people are looking to SwiftUI for inspiration. It'll still take some time to build and evaluate these solutions.
Re:Async Rust Is A Bad Language by Turskarama on Friday September 08, 2023 @10:33PM (#37441650)
It's "prefer composition over inheritance" though, not "never use inheritance".

There is a time and a place for it.

Re:Async Rust Is A Bad Language by radicalbyte on Tuesday September 12, 2023 @01:51AM (#37477297)
Which, as I said, results in you *usually* using composition :)
Re:Async Rust Is A Bad Language by lmm on Friday September 08, 2023 @10:19PM (#37441568)
Does delegate support delegating everything (except what you're specifically implementing for your own struct) yet? That's the way to do it.