Stop Using Object Oriented Programming In Rust (Do This Instead)

preview_player
Показать описание
In this video, I'll explain why you should stop using object-oriented programming in Rust and what alternative approach you should use instead. Say goodbye to the traditional OOP mindset and embrace a more efficient way of coding in Rust! #rustlang #objectorientedprogramming #codingtips
Рекомендации по теме
Комментарии
Автор

by the way I really liked that concept (reading nice articles together.) 🙂

morgomi
Автор

What is going on with your camera zoom?! Super distracting.

codeman-dev
Автор

This method is more efficient, but has the disadvantage of requiring a "Speak" overlay in the Animal "enum" with a "match".

DevRJPro
Автор

Thanks for the info! I don't think I have ever been this excited to learn a new language. I currently do web development using PHP and JavaScript. I have dabbled with C, C#, and C++ a little bit, but never got to far with them. So far Rust is holding my attention.

gman
Автор

The problem of OOP is that there is no standard way of sintax implementation, simula tried to do this but iwhat happened is that we have completely different abstractions in different languages .

h.s
Автор

Another way: Just create two vectors with one type of animal each -> no matching, no boxing, no enums, no traits

ClimateChangeDoesntBargain
Автор

but what if you wanted to expose the zoo? like, if someone external user had wanted to declare a new animal(e.g. a duck). this isn't possible with an enum

also all the animals will still be stored on the heap, since it's a vector and vectors allocate heap memory to allow for dynamic size. there is still an advantage: all you data is stored in sequence, and not via pointers to some random heap memory, but that's not what you said

wadsaek
Автор

Your example assumes you know all of the "kind" of animals before hand. In that case yes, there is no need for box<dyn...> . However, trait can be use as a contract where the implementor is unknown. Telling developers to STOP doing X or Y comes across as authoritative. In such a case cover all scenarios covered by your "STOP" doing..

shiftRightOnce
Автор

is this good practice?

fn sample(a: u8, b: u8) -> Result<T, Box<dyn std::error::Error>> {}

ok-alarm
Автор

i heard that humans, all humans, are born to think in OOP and then some kneecap themselves by going functional or abandoning inheritance for aggregation and i tend to agree. OOP is literally made for humans, it is modeled after intrinsic human reasoning patterns.

naninano
Автор

Also please post the article URL that you were reading please

JavierHarford
Автор

Is it a bad practice if first variant is large and second variant is small in memory?

kuqmua
Автор

Keeping watch for your next videos, this was a good one thanks! More Anti-Javascript brain videos please!

JavierHarford
Автор

And the problem is even worse if you do this in an async context.

Box<dyn MyTrait + Sync + Send> go brrrt

ShimoriUta
Автор

Won't it take more memory, because of the enum elements size?

ІванБоровик-эл
Автор

not the same thing mate. There are millions of animals on earth are you gonna make an enum for all of them?
You're missing the point of dynamic dispatch.

chudchadanstud
Автор

even c++ templates are easier to understand than rust

theairaccumulator