Rust Programming - No Inheritance

preview_player
Показать описание


Jeremy Chone:

Other popular Rust Programming videos:

Playlists:

Рекомендации по теме
Комментарии
Автор

OOP: everything is a class
Rust: everything is an algebraic data type

okie
Автор

One common misconception is that OO needs to be embedded in the language. You can model your entities with classes and implement without it. We just got used to have the full set

motbus
Автор

Cold shower everyone needs: There's nothing new after the Lisp.

orange
Автор

You can also implement common behavior on the `enum` type itself using a `match` statement to provide specific responses.

G
Автор

You can simply make a trait and implement it to the enum instead of each struct

shofr
Автор

My life long dream of typing Floor(Floor) is finally possible 😎, Poggers

randombleachfan
Автор

that reminds me of type classes in Haskell

filcondrat
Автор

don't really need an enum. could use a marker trait or use the trait itself

alvarozamora
Автор

Is there any way to force all structs in the enum to have a trait implemented?
So that if it gets removed from any of the structs, I can get a compile error.

marcusrehn
Автор

The problem I see most people coming from OO languages have with Rust is trying to shoehorn patterns intended to solve shortcomings of OOP, especially aspects of data modeling, and come to the conclusion that Rust isn't suited for such tasks. Rust is plenty powerful and easy to work with once you stop thinking in classes. Traits are not interfaces.

TheOrioNation
Автор

Inheritance, the shit we are forced to keep from our ancestors

NathanHedglin
Автор

I’m just glad that people are finally realizing the value of functions and composition.

Thanks for the video Jeremy.

jacobusburger
Автор

Interestingly, this is similar to some of the ideas I put forward in my PhD dissertation in 2010.

vanlepthien
Автор

It's very nice, I remember in some of my old game projects I would have several levels of inheritance, and hurts my eyes to look at that now.

Then I started using interfaces more it was just more dynamic and allowed for better generic code.

I feel like this works very similar to that, but more modular and just cleaner.

jonathanadamsson
Автор

This approach breaks the Open-Closed principle. Although it can be achieved with dyn trait, it’s a very verbose, impractical, and developer unfriendly way to achieve it
This is, for me, one of the biggest disadvantages of Rust

evols
Автор

that looks simple and easier to implement polymorphism.

Cptcat.
Автор

Inheritance means you can define an "Animal" struct and all animals(including pets) inherit eat, sleep and reproduce methods.

cerebralgeneratedimagery
Автор

Go also doesn’t have inheritance, classes ..etc so was a nice experience to program with

ko-Daegu
Автор

I thought the "Rust lacks X, therefore X is inherently bad" thing was just a meme

friend
Автор

I think there should be a way to auto implement a trait for the whole enum when all containing types implement the trait. Bsp:
Dog, duck, and cat implement noise. Then there should be a way to simply 1 line implement the trait for animal instead of needing a match that forwards the method to the individual versions.

redcrafterlppa