[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Cratera Compiler v1.0.0
- From: "Soni \"They/Them\" L." <fakedme@...>
- Date: Wed, 7 Aug 2019 21:05:47 -0300
On 2019-08-07 8:53 p.m., Egor Skriptunoff wrote:
On Fri, Aug 2, 2019 at 12:14 AM Soni "They/Them" L. wrote:
Inventory may not be self-contained. Inventory could reference
AFAIU "trait" in Rust is the same as "interface" in other languages.
You must implement interface for a class to be able to use it with
objects of this class.
In other words, a trait have to be "rooted" into a class.
That's why I don't understand what do you mean in "Inventory may not
Please give a non-trivial example about "a trait could reference
another trait" (in Cratera, not in Rust).
My intention was to understand whether the Cratera-like syntax
"a:b.c(x)" would bring additional expressiveness to Lua or not (I hope
it would, and I guess you can show an example).
But there are 10 replies posted already in this thread, and I still
can't imagine a real-life use case where traits could lead to a better
code (more readable/compact/etc).
Is traits really just a Rust-nostalgic feature (as you've said: "It's
just a different way of doing OOP"), which actually doesn't add new
power to Lua?
Lua has many ways of doing OOP, Cratera adds a new one on top.
With traits, one can do a "type-system ECS", that gets compiled to
extremely efficient runtime code. However, it requires recompiling and
doesn't exist (at all) at runtime, which is a bit different from what an
ECS would do.
Cratera is my attempt to bring that "type-system ECS" to the runtime.
The basic idea is that many of the patterns you'd use in Rust you should
also be able to use in Cratera.
You can also, ofc, inject your own traits into existing objects. You
can't do that with "OOP". But you can with Cratera. Which means it's not
(Rust *also* has support for "inject your own traits", sort of. It's a
bit limited, as you can't inject not-your-own-crate's traits into
not-your-own-crate's types, but it does exist. Sometimes you have to
wrap an object in another due to those limitations, which is something
you don't in Cratera. This limitation mainly has to do with traits being
a type property in Rust, whereas in Cratera they're more of an object
ECS is all about composition, and so are traits. This may be the only
similarity between them, but I'm more inclined to believe there are others.