New features in next rust releases

Ok good. However it remains all other points marked.
1.Dependecies are not trackable easly , it is not simple to have a overview of logical structure, it is not simple to refactor or remodelling
2. sheep is not a dependecy of animal. Logic is broken

I'm not going to keep repeating myself. Rust is not Java. Go read that thread I linked.

The problem is not bound to specific language. It is abstract.

Dependecies are not trackable easly

On the contrary. If a struct composed of many smaller structs just by looking at the source you know what methods and fields are available for you - all public methods and fields of the member structs! It's more painful to hunt down inheritance chains just so you can figure out from where do you have method foo() and what does it do.

sheep is not a dependecy of animal.

Marker traits are thing. You can express trait hierarchies to represent what you'd do with class hierarchies. But you can do more with them, like marking... well traits that are general and can't be tied to a specific hierarchical class.

Like a sheep can have fur, a coat can have fur but a coat is not an animal... and not all animals have fur, not even all mammals have fur.

trait Animal {}
trait Mammal {}

// If it's a mammal it's also an animal
impl<T> Animal for T where T:Mammal {}

// not all mammals have fur, even a coat can have fur
trait HasFur {}

trait Fluffy {}
impl<T> Fluffy for <T> where T: HasFur {}

struct Sheep {}

impl Mammal for Sheep {}
impl HasFurr for Sheep {}

struct FurrCoat {}
impl HasFurr for FurrCoat {}

So if you don't have interfaces (traits are quite close to interfaces in a way) in the language you'd end up adding some intermediate FurryMammal class and a FurryThing class; or do multiple inheritance to inherit from FurryBase and Animal at the same time. (Playground)

I think most of the thing you'd do with class hierarchies can be done with traits, sometimes in an even nicer way (like the HasFur case).

1 Like

Personally I think Rust has a rich enough set of features that it's going to take me a long time to get comfortable with them all. I'm suspecting more and more everyday that I may never reach that state, everyday I see code snippets and discussions here that totally baffle me.

As such I think layering on the complexity of syntax and semantics required for "classes like in c plus plus" with whatever mechanisms would be totally impossible to work with. Even if it were even possible to implement.

Aside: One might have noticed my complaining of headache when trying to fathom the deep complexity of code that turns up here. Fear not, I'm not giving up on Rust. I'm happy that I can write my own code in Rust as if I were writing C or Pascal, as far as it will allow me, whilst at the same time with crates like Rocket I can get bigger things done almost as easily as using node.js, with a lot more confidence in the outcome!

5 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.