Тёмный

Prime Reacts: The Flaws of Inheritance 

ThePrimeTime
Подписаться 467 тыс.
Просмотров 314 тыс.
50% 1

Recorded live on twitch, GET IN
/ theprimeagen
original: • The Flaws of Inheritance
author: ‪@CodeAesthetic‬
MY MAIN YT CHANNEL: Has well edited engineering videos
/ theprimeagen
Discord
/ discord

Наука

Опубликовано:

 

10 фев 2023

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 742   
@Proletariat-intifada
@Proletariat-intifada Год назад
I love how CodeAesethic just came from nowhere, proceeded to release some bangers and now is easily one of my top 3 fav programming youtube channels lol
@animowany111
@animowany111 11 месяцев назад
Nemean was even crazier, just dropped the Quake q_rsqrt video and got like a million views and tens of thousands of subscribers with only one video on his channel
@andrewhooper7603
@andrewhooper7603 11 месяцев назад
@@animowany111 Not programming, but Bobby Fingers' view to upload ratio is insane. Guy comes out of nowhere and drops a 20 minute video that is currently sitting at half a million views 10 months later.
@XDarkGreyX
@XDarkGreyX 11 месяцев назад
And mia for a while
@pixelpox11
@pixelpox11 6 месяцев назад
I dislike quite a few of his videos. They feel like they were made by person that writes 100 lines of code and names it a project, and therefor it's not relatable to actual production code.
@cheerwizard21
@cheerwizard21 6 месяцев назад
@@pixelpox11 I agree with you. Even the actual name of channel "code aesthetics" already sounds very weird, since code is not a book or poem, it's a machine instructions :)
@theondono
@theondono Год назад
Inheritance only works on paper because it forces you to go backwards. Programming tends to happen bottom-up, you start with some core functionalities, and write more and more stuff on top. OOP requires you to work top-down, which necessitates knowledge of the full problem upfront. That’s why it works on paper (small exercises) but fails on the true stuff. I’m not sure if you can build inheritance to work the other way round, but it’s clear Rusts traits are much closer to this, that’s why they feel nicer.
@ThePrimeTimeagen
@ThePrimeTimeagen Год назад
agreed
@gagagero
@gagagero Год назад
That's a really good way of describing it. Tbh, I prefer inheritance over composition, but it requires much more work to do it right.
@prestonrasmussen1758
@prestonrasmussen1758 Год назад
I learned to program from a top down approach and I definitely find it very useful for working out problems. I barely ever use inheritance though
@RobertSmith-lh6hg
@RobertSmith-lh6hg Год назад
Underrated comment. I would expect if one were to poll pro-OOP vs anti-OOP programmers there would be a strong correlation between top down vs bottom up design mentality.
@MrHaggyy
@MrHaggyy Год назад
Depends on what your true stuff is. In embedded stuff, especially safety critical stuff you get a much tighter contract than any "big tech" company has ever written. Not uncommen to get a close to full coverage unit test alongside a project. But most of the time we use inheritance to fit some code into memory constraints. Something most desktop or server programmer don't need to bother with. At least not to the extend of, if we really need the bigger chip we lose millions of dollars.
@mmzzzmeemee
@mmzzzmeemee Год назад
i'm a fan of that channel, the way he explains is quite like he's the 3blue1brown of programming.
@WillEhrendreich
@WillEhrendreich Год назад
And that should be emulated everywhere!
@JohnZakaria
@JohnZakaria Год назад
I would say the 3blue1brown of CS is reducible, he goes deep into CS topics
@mayabartolabac
@mayabartolabac Год назад
yeah code aesthetics is more like the 3blue1brown of medium articles
@liviousgameplay1755
@liviousgameplay1755 Год назад
I'd say he has some of the same traits of 3blue1brown, don't want your comment to get outdated if 3blue1brown changes how he makes vids.
@jffrysith4365
@jffrysith4365 6 месяцев назад
@@JohnZakaria I really don't think that calling codeAesthetic the 3blue1browne of CS is very accurate, programming is significantly more accurate. Like the topics he covers is: - how to make code easier to read - how to make code more extendible - how to design code effectively (yes this is a mix of the above). What he isn't covering is: - how the computer works fundamentally - complexity analysis - math What he's covering is significantly more accurate to call it programming than CS. And this isn't a bad thing btw. I find it funny when people think monkeybrain "CS good, programming bad". But saying that, they aren't the same topic, computer is understanding why we design code, how we can analyse code, and even lower how a computer works. It's even to find the limitations of code. Programming is a part of CS, and this is what CodeAesthetic is explaining (really well).
@alfred0231
@alfred0231 Год назад
I like Jonathan Blow's take on design paradigms: " The benefits are obvious because the thing got proposed because of its benefits and you'll hear about the benefits. The cost tend to be subtle and/or swept under the rug by the people that want to sell you on the benefits." - 'Jonathan Blow on unit testing and TDD' (7:25)
@michaelharrington6698
@michaelharrington6698 10 месяцев назад
Amazing commentary
@thekwoka4707
@thekwoka4707 Год назад
I definitely agree with that whole "when you're shown this it makes perfect sense". Like the idea of inheritance is smart, and practical, and obviously a decent way to do it. Then you see a codebase that actually uses it and it's such a complete cluster fuck and it's so hard to keep track of what anything is supposed to be.
@prestonrasmussen1758
@prestonrasmussen1758 Год назад
I think the issue is that inheritance is often taught with examples that describe existing properties or functionality. People will often use the example of having a square class that inherits from a polygon class. The issue is that this works because you’re classifying existing functionality. When creating something new, the analogy falls apart. Companies don’t have a Vehicle blueprint that they then extend to either get a Car blueprint or a Motorcycle blueprint to the build. They build the Car and Motorcycle completely separately.
@BillClinton228
@BillClinton228 Год назад
Yeah I think people take it too far, I worked for a company which only employed "Senior Developers" and had 2 juniors to do really menial stuff. Some of the software those "Senior Devs" wrote had so much inheritance if you wanted to go down the rabbit hole it would take you hours to figure it out. Thats really bad code architecture and I don't think you can call yourself a "Senior" anything if you don't think about how your code reads to a person who's not familiar with the structure.. At the same time though, these devs would be very critical of how you named your classes and methods, so you don't care about how your code reads but you really care about what a class is called? That doesnt make any sense to me.
@moonasha
@moonasha 11 месяцев назад
doesn't it just depend on how it's implemented? For example, in my game, every item inherits from the base world object class. This class handles temperature and other things like that, so anything that affects temperature can easily do that. Then an example of an item is a tool. The tool has base things like, how it can hold items, how you can remove items from it, and whatnot. And then there's specific tools that have their own specific behaviors for items in the tool. I just want to know, how in god's name would you approach any of that without inheritance? I genuinely want to know. And I think if done well it's just common sense what things are supposed to be
@Mitch_Crane
@Mitch_Crane 11 месяцев назад
​@@moonashaDoes your game have weapons? If so, would a weapon be a subclass of item? What would happen if I wanted a hammer to act as both a tool and a weapon, or a baguette as a weapon and food etc. This flexibility might not be necessary for whatever you're building but it's something to consider
@romannasuti25
@romannasuti25 11 месяцев назад
Yep, and honestly there’s some codebases that spoil us rotten and make it seem so good because the focus is so constrained that object orientation is good. Perfect example is game engines and really popular large web frameworks. Even then, there’s limits and people end up running into issues. Want to see a HORRIBLE OOP library? Read LangChain, and try to figure out how Conversational Agents pass through chat_history, this nearly drove me mad. If you’re wondering why it’s that way, they release a new version of the library roughly every 1-2 days (absolute chaos of a commit history) and they prioritize maximum flexibility above LITERALLY ALL ELSE.
@name_cpp
@name_cpp Год назад
LMAO the curly brace thing at the beginning, finally someone else who HATES newline braces
@ThePrimeTimeagen
@ThePrimeTimeagen Год назад
it hurts me
@MangoDev_
@MangoDev_ Год назад
and yet so many different style guides say not to >:(
@NeoChromer
@NeoChromer Год назад
Thats actually a best practice for # and Java
@NeoChromer
@NeoChromer Год назад
C#
@samochreno
@samochreno Год назад
@@NeoChromer not for c#
@IanRiley915
@IanRiley915 Год назад
I love how Prime calls out CodeAesthetics for the next line curly braces and then rhetorically asks whether it's C# because C# standards infamously use next line curly braces. Then I double check the code and realize that it is actually C# code.
@sadboisibit
@sadboisibit Год назад
Holy moley I think it's been at least 10 years since I've heard anyone bring up Microsoft XNA.
@ThePrimeTimeagen
@ThePrimeTimeagen Год назад
yeah... i did it!
@TehKarmalizer
@TehKarmalizer Год назад
Inheritance has its place. It can definitely get out of hand. Composition has its issues, but he made the point that some of those issues might be due to putting too many responsibilities on the composes objects. Some of the issues with inheritance can surely be traced to the same.
@ifeoraokechukwu1346
@ifeoraokechukwu1346 9 месяцев назад
Spot on!
@nonnodacciaio704
@nonnodacciaio704 Год назад
I use both new line and same line curly braces at work depending on the language and their relative best practices, so yeah you don't die from it
@thfsilvab
@thfsilvab Год назад
"Avoid protected member variables with direct access" - when I was learning Android Development in Java, this KILLED my motivation entirely when trying to reason with the code, some view operations intensively use protected members from the parent class and I kept asking myself where those members were coming from...
@aoeu256
@aoeu256 Год назад
Why not use the Python naming conventions to add _ to protected and __ to private (name mangled).
@cheerwizard21
@cheerwizard21 6 месяцев назад
Just add correct code convention. m_ - protected member variables. p_ - private variables. Well in any case you can just look into a codebase and find what this member variable is actually doing. I didn't really understand your concern.
@sfulibarri
@sfulibarri Год назад
Never heard of the triple method but thinking back, its seems to be categorically true in my experience. I've seen lots of new products fail after months of effort because we didn't know all the things we learned in the first attempt but the 2nd pass usually ends up shipping and doing well. Whenever I've worked on proprietary framework level things it does seem like it takes at least two but often three passes for it to be fully baked and desirable to the org.
@tokiomutex4148
@tokiomutex4148 Год назад
Who needs inheritance when you have enums and traits?
@ThePrimeTimeagen
@ThePrimeTimeagen Год назад
these are facts you just hold my heart in a lock, i swear
@T33K3SS3LCH3N
@T33K3SS3LCH3N Год назад
I got to work on an old project where all the important bits happened in business objects that were pure spaghetti of inheritance. EVERYTHING happened through protected variables and methods. You would see a 5-line function and think that that should be easy enough to understand... but then it ends up triggering 500 lines of code across 5 levels of inheritance. And it would go up and down, up and down... Line 1 out 5 executes something in its parent, but that is passed right through to the grand parent. So the grand parent does some things, then passes it to the GRAND-GRAND-parent, which executes like 10 lines before it goes back to the grand-parent. The grand parent does a few more lines before calling something that passes through to the GRAND-GRAND-GRAND parent... which calls some completely other module... and from there it falls back to the original child object I was working on. One line done, get ready for 4 more...
@jacoboblanco1555
@jacoboblanco1555 Год назад
That description of developing software in a 3ply-fashion is brilliant. Totally tracks sometimes you build it to understand what it does, then build it to make it ready for others, then build it to make for you and others in the future.
@jaysistar2711
@jaysistar2711 8 месяцев назад
The file savers should really just be functions that take some sort of writable object, an image, and options. There really doesn't need to be a class, since that just creates an unnecessary alias to the image and options.
@marcs9451
@marcs9451 5 месяцев назад
the OOP mind cannot comprehend this
@thesenamesaretaken
@thesenamesaretaken 3 дня назад
Nooo you need to allocate a FileSaver object to the heap so the garbage collector doesn't get bored.
@NithinJune
@NithinJune 4 месяца назад
dependency injection was our bread and butter in high school robotics. We split the robot into subsystems and everything would be injected into relavent methods and classes. Was a massive pain
@CodeTalker23
@CodeTalker23 Год назад
the rust default impls of traits is available in C# as well (also C# allows Data Members in interface but not entirely since Properties are methods and not fields so it feels like it does when it actually doesn't)
@khatdubell
@khatdubell Год назад
Agreed. Its also existed in c++ since forever. Not sure why he was gushing so much about it in rust, its not a new concept
@oliverdenton2833
@oliverdenton2833 Год назад
I quite like these 2nd channel videos. The volume of clips and more of a focus on Actual Programming concepts, rather than the 'hot-takes' to just drive engagement like the main channel. I like seeing the M who just likes to help people get better.
@m4rt_
@m4rt_ Год назад
2:40 that is because they don't tell/show you how painful it is to change the structure of it after it has been coded . They show it from the perspective of a world where everything is easy, and is correct on the first try. (I have not gone to college for programming, so I don't know if that is the case, but it sounds like that is why)
@y200sub
@y200sub Год назад
I have studied OOP in college a long time ago and this is exacyly how it is shown, OOP has its place but we have gone too far in making everything abstract and that in turn made things worse.
@khatdubell
@khatdubell Год назад
Schools teach you how, not why. So when they introduce a new hammer, people want to try and hit everything that looks even remotely like a nail with it.
@kiyotaka627
@kiyotaka627 Год назад
I love this channel and the long video format, for me that can't manage to watch the streams, this is gold
@st-jn2gk
@st-jn2gk Год назад
your advice on capital D Design and your 2-level way of writing production code is really REALLY helpful. Thank you.
@Hazanko83
@Hazanko83 Год назад
I love my next line squirly braces... especially in a language where things can occur between functions and their scope, such as declaring a function const, or member initializers, or metaprogramming(?) such as std::enable_if, or any other number of things. Lines come free, readability doesn't. MyClass::MyClass(int value_1, int value_2) : member1(value_1), member2(value_2) { //stuff }; ^^ isn't too bad until you have longer type names, or more parameters, or more going on with the class/function/etc. MyClass::MyClass(int value_1, int value_2) : member1(value_1), member2(value_2) { //stuff }; ^^ is so much easier to read and is much easier to be consistent with in different situations.
@demolazer
@demolazer Год назад
So true. When learning programming, inheritance seems so logical and endlessly useful. Yet much of the more advanced programming literature/videos points out that composition is often better.
@rumplstiltztinkerstein
@rumplstiltztinkerstein Год назад
Now I understand why Rust traits work in such a way. It has the advantages suggested in this video, without the disadvantages that comes from inheritance.
@ThePrimeTimeagen
@ThePrimeTimeagen Год назад
yep
@betterinbooks
@betterinbooks Год назад
trait system is so good I wish it existed everywhere else.
@rumplstiltztinkerstein
@rumplstiltztinkerstein Год назад
@@betterinbooks I agree. Once I was coding a server backend. I created the struct for the internal state that is going to be accessed by the endpoints. I then created a trait with the methods for accessing the state. For each endpoint, I created a unique trait for it with the behavior of that endpoint. The trait applies to any struct that implement the original trait type. Thanks to that, each endpoint is its own trait. We just have to implement these in the state type. Instead of one file with all the business logic, I was able to divide each into its own trait. Extremely easy to scale. Loved it so much. Using that structure, we could have several people working and pushing to the same repository at the same time. Each developer needs to simply work on their trait.
@jakal13
@jakal13 Год назад
This is the first reaction video I liked - ever. You complement each other so well. It is like you inherit his evil genius and implement an emotional amplifier of profanity into it.
@spicynoodle7419
@spicynoodle7419 9 месяцев назад
Data duplication is good when it leads to a more decoupled codebase. You don't always want a giant users table with 100 columns because every part of your system needs parts of the table. Adding an extra column suddenly breaks everything because other parts of the project are now trying to insert null into the new column.
@FrankHarwald
@FrankHarwald 9 месяцев назад
"Who puts curly braces on the next lien?" Most C programs from the Unix world is written in this style - except kernel hackers & GNU software.
@5h4ndt
@5h4ndt 3 месяца назад
I learned it that way, but have since converted.
@alek282
@alek282 Год назад
I really connect with Prime's idea of 3 stages of writing an application. Coming from embedded development, I am very used to separating data and methods on data, and even now that I work on higher plane of abstraction I often always write my first version as a combination of data containers and methods on them. What I find is that often times on subsequent re-factors that pattern alone is sufficient without even going towards OOP way of structuring your code. I am not generally opposed to it, but in my experience it's far easier to first do the simplest thing first (data + methods on data) and if you spot patterns - refactor them however it makes sense to refactor them. Using classes to structure your code from the beginning IMO is hard to get right even for experienced devs, inheritance or not, you are still effectively dealing with lots of local namespaces and are dealing with "this object owns this and that object owns that", if you then need to share some data, it's more work to make these changes compared to if they were simply passed in as a parameter to some method I also feel that having a very clear way of identifying data within your program is often very beneficial and illuminating. I suppose this is more towards data oriented programming approach
@HrHaakon
@HrHaakon Год назад
My experience is that if you're having a clump of data, and then some operations on that data, it's pretty easy to get it done using OOP. Will you have to refactor a lot? Maybe. But it's pretty easy to think in terms of. Then again, I model the database FIRST these days, as nailing that is pretty reasonable, and then the OOP layer on top handles messaging between the data model and the front end. So it's like the controller in the way MVC was originally conceived. It works really well for enterprisey solutions.
@harleyspeedthrust4013
@harleyspeedthrust4013 Год назад
I did java for several years and i suffered at the hands of forced inheritance. Now i use literally anything other than java and i hate inheritance because it overcomplicates everything and forces you to fit the problem to the code rather than the other way around
@imblackmagic1209
@imblackmagic1209 Год назад
i use inheritance only for derivatives, the child classes only add new functionality, they may or may not alter some functionality (i usually prefer not to), and maybe implement some virtual methods to fit an API (or use interfaces) aside from that, i avoid it like the plague, if it's not needed, dont use it
@HrHaakon
@HrHaakon Год назад
C++, JavaScript, Python, C#, TypeScript and fucking COBOL has inheritance, and are fine, but not Java? Do people just not know how to write Java or something?
@harleyspeedthrust4013
@harleyspeedthrust4013 Год назад
@@HrHaakon I almost didn't reply because your comment severely missed the point, but I have a minute so I'll explain again: Java forces you to use classes and heavily encourages you to think about the problem in an object oriented way. (You don't have to of course if your classes are just function containers or bags of data but that is terrible Java. and as someone who knows how to write Java I'm sure you wouldn't approve.) This is not good because most problems are not cleanly represented in the pure OO inheritance world of Java. So while other languages may have inheritance, they also have more sensible ways of modeling code so that you never have to touch inheritance. Caveat with TypeScript: you should know about prototypical inheritance but you rarely have to actually use it. You can write a NodeJS application in TS that doesn't touch prototypes or explicit classes ever.
@HrHaakon
@HrHaakon Год назад
​@@harleyspeedthrust4013 You don't need to use a lot of inheritance in Java. Stop trying to sneak in that assumption.
@harleyspeedthrust4013
@harleyspeedthrust4013 Год назад
@@HrHaakon I didn't sneak it in. I made it pretty clear that you don't have to use inheritance in Java but if you don't then you're writing what Java people would call "bad Java." Maybe next time read the comment.
@marioamatucci
@marioamatucci Год назад
hey dude- plz make a video explain dependency injection and inversion of control for the masses
@SmartK8
@SmartK8 Год назад
His curly braces are symmetrical. That's real esthetics - real beauty. 💯
@iwky1930
@iwky1930 Год назад
I love new line curly braces looks cleaner and more symmetrical.
@Sammysapphira
@Sammysapphira Год назад
I agree with you on smooth scrolling. There's a reason why scrolling was originally in steps and it's because it causes less motion sickness. I am not particularly prone to motion sickness, but I find it much harder to read stuff when they're smooth scrolling, even on a 144hz monitor. The greatest demonstration of this are youtube live comments vs twitch, where the former is smooth scroll and the latter is bulked into steps. Twitch chat is legible when it's being -SPAMMED-, I'm talking 100 messages a second spammed. RU-vid chat is barely legible with 5 messages per second, because it's constnatly scrolling up, there's no rest for your eye to actually read the words.
@Joker22593
@Joker22593 10 месяцев назад
Vertically aligned Squirrely Braces is 1000x more readable. This isn't the 1970s where newlines are expensive.
@SuperJJAlexander
@SuperJJAlexander Год назад
Code Aesthetics messed up with the inheritance diagram right before moving on to composition. The object on the right started with only blue and red square but ended up as a child of the green and blue object.
@Jabberwockybird
@Jabberwockybird 4 месяца назад
That's kinda the point. If your system is too messed up with ideas that are more complex than they need to be, then you'll make mistakes
@marcs9451
@marcs9451 Год назад
The solution to the image problem the video presents could be far more easily solved in practice with a single Image struct and some associated methods for editing + separate load/write functions to different image formats (maybe a ImgConverter interface if needed). The video is good but usually these OOP examples are overly complicated for no reason other than trying to fit a mental model of classes
@MasterHigure
@MasterHigure Год назад
That's the point, though. You have some class that works just fine, but then one day you want to extend it. Doesn't matter how cleverly your inheritance structure solves the current requirements. The moment a new requirement is added, the resulting refactor is huge. Sure, you can solve the problem given here, with a drawable / non-save-and-load image just fine if you know that that's a requirement from the get-go. But then something new comes along.
@marcs9451
@marcs9451 Год назад
Actually the method I proposed is way more flexible, as the image manipulation logic is separate from the conversion logic. Want more formats? Simply write a new save/load function pair and pass an Image struct to it.
@TheBrazilRules
@TheBrazilRules Год назад
@@marcs9451 How is writing more functions different from having them as methods in the classes?
@aoeu256
@aoeu256 Год назад
@@MasterHigure The problem with inheritance when I used it (maybe bad at OOP) is mutation/global state is order dependent, and if you inherit something the child classes may sometimes want to call the super method first before the body sometimes last and it could lead to subtle bugs because of state, you sometimes have to have the super method be a higher order function so it can be called around your code. Also sometimes you have to have the parent call the parent version of a method other times you want the parent to call the child method...
@fluffydoggo
@fluffydoggo 11 месяцев назад
@@MasterHigure extension methods 😎
@sentientmachine2850
@sentientmachine2850 Год назад
I already watched every single video, super cool insights
@Danielo515
@Danielo515 Год назад
I already watched this video, but watching again along with you was so fun…
@multiHappyHacker
@multiHappyHacker 5 месяцев назад
Anyone that doesn't appreciate the proper style of curly braces on their own line is not my programmer.
@dustmighte
@dustmighte 5 месяцев назад
I believe pretty strongly inheritance is only good for composing orthogonal behaviors. Inheritance for specialization opens the door to overriding, calls to super and having to understand multiple versions of the same artifacts but jumping back and forth between modules to understand what each does. My brain doesn't compute that.
@nekodjin
@nekodjin Год назад
"What is this, C#?" he says, while staring at a snippet of C# code. Yes, in fact, it is C# :p
@stevo728822
@stevo728822 6 месяцев назад
I've been viewing your back catalogue of videos and this is by far the best one so far. Started programming with COBOL and DB2 on IBM mainframes back in 1990. Now I just do Godot and Python for selling small games off Steam.
@johnt1342
@johnt1342 8 месяцев назад
25:03 Yeah, I've thought about this a bit and have been curious if it's not a bad idea to have an `embodies`, `compose`, or a similar keyword. The idea would be that within your class you would say that it embodies another object, which you can then access it's methods as if it's your own, but they would be private. Mostly a convenience feature, it would benefit from the IDE informing you which component you are fetching the method from, but I haven't thought of a scenario where it would be dangerous (yet.)
@timedebtor
@timedebtor 2 месяца назад
This feels like almost an exact replica of a Raymond hettinger talk, but there was obviously a lot of care and love put into visualization and video development.
@TRobStudios
@TRobStudios 9 месяцев назад
Did XNA in college senior year, I loved it. Glad to hear I wasn't the only person who used it. I made a pacman and tetris clone in it and was so excited to deploy it to the first generation of windows 7 phone. RIP windows 7 phone, never got flash support and was too late to the market
@mrrolandlawrence
@mrrolandlawrence 8 месяцев назад
as a silver haired coder from the 1980s OOP & inheritance was the bees knees. on paper. awesome. in reality - i watched programmers inherit the crap out of stuff, till it was just crap. So deep that even a Matryoshka doll would have gasped. also kudos for your music tastes there with miss monique.
@guillermocava3568
@guillermocava3568 Год назад
The triple method - harambe moment at 10:05 is pure gold
@RedHandedBug
@RedHandedBug Год назад
Oh baby a triple!
@SaHaRaSquad
@SaHaRaSquad Год назад
It's indeed the best way to produce quality software. Developers who think they can do it right the first time just haven't learned that lesson yet. RIP Harambe
@aonodensetsu
@aonodensetsu Год назад
i can relate to making things three times, finally finished up my third full rewrite of my github repositiories today and beginning to do the same for my portfolio website
@mattrs1
@mattrs1 10 месяцев назад
An example of where inheritance makes sense is Pokémon: you have the definition of a pokemon(name, evolution, moves it can learn, abilities it can have, base stats). Then you have a class to express a pokemon in your team (has ivs, evs, only four moves out of whatever it can learn, a personality, only one ability) and from the pokemon class it helps to validate if it can learn the move, calculate actual stats based ob ivs and evs and so on. But then I wouldn't do a battle class that inherits from pokemon, items and so on
@loganrogers4560
@loganrogers4560 Месяц назад
I know it's an old video but I'm so glad I found this channel. RU-vid addiction is my greatest struggle as a junior dev that just has been coasting in his work. I know this channel is primarily entertainment but replacing some of the political trash that I normally binge with your content is starting to improve my mindset and problem solving skills and I'm noticing improvement and growing competence at work as a full stack dev. Coming from a game dev degree that I'm sometimes not proud of you're really helping me fill gaps in my knowledge base that I missed in my formal education. That said I'm happy I went to college for game dev, got me into coding and even if I was disillusioned by the industry during salary negotiation it got me started down this path and it's something I'll never take back.
@moonasha
@moonasha 3 месяца назад
my current strategy is, "Can I do it with an interface?" If the answer is yes, I don't use inheritance. There are some cases though where inheritance is super useful, but I live mostly in the game coding world so it probably doesn't apply elsewhere. As an example, a game would have a base object, that keeps track of temperature, who owns it, etc. Then more specific objects with certain functionalities can inherit from it, without having to duplicate a bunch of code. Basically for me it comes down to how much code you're duplicating
@MorningNapalm
@MorningNapalm Месяц назад
I use next-line braces. It puts a little extra vertical space in exactly the right places.
@qm3ster
@qm3ster Год назад
How to execute: 1. Dicks out for Harambe 2. Shit code 3. Full rewrite no matter what "statistics" tells you Took me over 10 years to understand how true this is
@ccgarciab
@ccgarciab 11 месяцев назад
This is precisely why typeclasses/traits work so well
@djl3009
@djl3009 Год назад
@2:14 -- yes, it makes perfect sense on paper ...just like the waterfall model for development made perfect sense on paper.
@YourComputer
@YourComputer 11 месяцев назад
The video doesn't present a problem with inheritance. If anything, all it does is reveal the necessary foresight and experience required to construct a feature-rich, well-designed API. It just so happens that the lack of such things are naturally inherent in humans, and this by default. Also, inheriting from an interface *is* inheritance.
@realtimberstalker
@realtimberstalker 18 дней назад
I great thing I heard to use was "Is" vs "Has". If something "Is" something else, then you use inheritance. If something "Has" something else, you use composition. For example, "Is" a Png an image? No. Png "Is" a format for saving images. As are the other formats. So we can separate these from image and have them inherit from some ImageFormat class which contains methods to take in an image and save it and return a saved image. "Is" a DrawableImage an Image? No. But a DrawableImage "Has" an image that it can draw to. So we can separate DrawableImage to its own class, and give it an image to perform drawing operations on.
@Kitulous
@Kitulous 2 месяца назад
it's C#, the opening brace on a separate line is the default and the norm there. the methods that start with a small letter, though... A SIN! AN UNFORGIVABLE SIN! the only things that start with small letters in C# are local variables, parameters and private fields! (private fields also typically start with _ but then a small letter follows) (I'm talking identifiers, of course keywords (int is also a keyword) start with small letters)
@likwidmocean
@likwidmocean 11 месяцев назад
The emotion behind "and then all the sudden shit goes so wrong" got me to subscribe.
@juanandrade2998
@juanandrade2998 11 месяцев назад
Imo the only good way to have this conversation is by looking at what the compiler does. For example each time the compiler sees a dereference (dot operand) it performs an extra instruction for null checking, while local variables are accessed directly. And if we get even more exquisite... Local assignment(dereferencing a field to the method stack is supposedly even faster... But the assignment tradeoff needs to be matched against the number of times the reference will be accessed.
@user-oj7uc8tw9r
@user-oj7uc8tw9r 23 дня назад
The performance hit is probably insanely negligible since many instructions are pipelined and executed partially in parallel. By this logic, all OOP languages would be slow, but they arent Inheritance is not bad. The code reuse alone is much better than any type of convoluted dispatching argument. The best, most bug free code is code that is never written or re-written. Without inheritance, you are guaranteed to write code over and over for no reason. People just really dont understand inheritance in my opinion. And if you are so concerned about performance, write everything in assembly.
@juanandrade2998
@juanandrade2998 23 дня назад
@@user-oj7uc8tw9r I like OOP, but I won't deny it's drawbacks, specially in such limited scope tests like a simple loop. JIT is better at optimizing code than a well written C, maybe even a very good C. But the time it takes for the optimization to kick in... Takes some time. Another thing about VM languages is that their compilers are really not that smart... Maybe because of exceptions and extensibility but devirtualization should happen a lot more... yet is something that rarely happens. Each virtual call adds a whole instruction... which eventually adds up... Each extra instruction call is ONE LESS op code of instruction sequence, which is one less op code for the speculation sequence. The worst offender is that each virtual function call forces a memory order boundary, which means that the compiler is not allowed to interleave beyond the virtual function call... this is the worst offender.
@juanandrade2998
@juanandrade2998 23 дня назад
@@user-oj7uc8tw9r I love OOP, I just wish compilers were more confident when devirtualizing and parallelizing up front, maybe even add keywords to hint devirtualization. Also I'd love for compilers to not implement 'freezing' so strictly, instead make a flow graph and ignore the constructor memory barrier if the logic allows it... do it up front instead of JIT. This would allow swaths of lengthy op code sequences... Making massive and faster speculations uninterrupted. I keep being told that if full de-virtualization would be applied, some pattern would break when dynamic dispatch is not obeyed, yet I keep getting some weird/nonsensical and incomprehensible examples of this...
@Panakotta000
@Panakotta000 9 месяцев назад
My biggest problem with composition in Rust, especially those default implementations for functions of a trait... is that when these default implementations rely on state, you always have to provide accessor functions within the trait... and in rust you often need two for the same value, one for immutable and one for mutable state... this forces the struct that implements said trait, to implement these accessors even if they just point to a single field in the struct... depending on how many such traits you have this can cause a lot of boilerplate code
@MarcLucksch
@MarcLucksch Год назад
Java Swing goes full in on inheritance, and it's the only one case that I found actually useful and easy to hook into. Building UI, quickly changing a draw method here, or making a table behave like a tree. Once I got it, it was really easy. But designing that stuff myself to be flexible like that, no thanks.
@TheGreatDazod
@TheGreatDazod Год назад
I don’t know if this purposeful or not but I appreciate here how your personality feel like you are channeling Dane Cook is he was a software engineer and I am here for it 😂 first video of yours I’ve watched to completion but I’ll be watching more now 😮
@laharl8417
@laharl8417 Год назад
!Wow its a really nice video! I learned a lot!
@vovcheable
@vovcheable Год назад
Sendi Metz gave a great talk on this subject with guilded rose kata
@stendaneel4879
@stendaneel4879 8 месяцев назад
6:25, just use the virtual keyword instead of abstract. This will allow you to define and write code in the function inside the abstract class. This allows you the ability to override it in inherited classes while not being forced to.
@Wreighn
@Wreighn 5 месяцев назад
My brain partially breaks every time I see someone open curly braces on the next line.
@jonaskoelker
@jonaskoelker 9 месяцев назад
> A [pee enn gee] is called a ping I'll update my pronunciation in a giffy.
@DaveRogers-et4cv
@DaveRogers-et4cv Год назад
Those curly braces on the same line are standard practice in C#. Any linting tool would complain if you did anything different to that. They are called automatic properties and they are awesome.
@Ormaaj
@Ormaaj Год назад
Meme, not standard practice. Entirely due to historical VS defaults.
@DaveRogers-et4cv
@DaveRogers-et4cv Год назад
@@Ormaaj You are wrong.
@Ormaaj
@Ormaaj Год назад
🤣No I have superior taste.
@DaveRogers-et4cv
@DaveRogers-et4cv Год назад
@@Ormaaj Wrong about that, as well. That's the thing with you. Always wrong.
@Ormaaj
@Ormaaj Год назад
Whatever newline-curlybracer. At least I'm not wasting all the world's supply of vertical whitespace
@martinbecker1069
@martinbecker1069 Год назад
When you were describing how default implementations can make use of defined but unimplemented methods, that is default implementations can only call methods it knows about (other methods defined within the trait), does that "methods it knows about" also include methods defined by traits that this trait requires to be implemented?
@HrHaakon
@HrHaakon Год назад
In Java, this is pretty simple: any method the interface knows about can be used. So I assume Rust must do something different, because being similar to Java is a deathly sin.
@pinatacolada7986
@pinatacolada7986 Год назад
Exactly. The absolute best way to code is to fever dream a quick working example. Take a step back, go for a walk, think about what just happened. Then start again from scratch. I guarantee you won't need OOP if you really think about what code is necessary.
@nyankers
@nyankers Год назад
multiple inheritance is great when it's done well
@halfalligator6518
@halfalligator6518 3 месяца назад
It just depends how many "branches" of your core class there end up being. If say there are 30 variations.... then you'll probably have a hierarchy of inheritance with 3 or 4 "generations" to stop objects from inheriting too much. That can require a lot of pre-planning and can easily end up a mess. I'd usually prefer to use the modular approach of composition to form each sub type, but it really just depends on how many variations we plan on using and how worried we are about memory.
@songlover5973
@songlover5973 5 месяцев назад
Someone finally says gif the right way. Thanks for setting up my day to be a good one.
@CodyDBentley
@CodyDBentley Год назад
24:06 This describes my hatred of DI *frameworks*. I love dependency injection and I use it a lot in Go, but the dependencies are created manually and passed around in code in such a way that's easy to trace and debug. I hated DI in other languages (C#, TS [Angular], PHP) because it almost always involves some sort of DI Framework that over complicates everything and turns DI into a magic global black box that's a pain in the ass to debug and manage configurations.
@tr4x1ymus
@tr4x1ymus 5 месяцев назад
i remember xna, and it will stay there, in my memories, haunting me as i sleep.
@andrewgjkgjk
@andrewgjkgjk 6 месяцев назад
@interface was one of the reasons I loved Obj-C in the 90s.
@oakley6889
@oakley6889 Год назад
C# is partially written using C#, so you can pass in its own compiler. My Lecturer did his pHd on AI optimising and writing code.
17 дней назад
I do inheritance, but it's almost always just one level, very rarely two. I often need very slight variations on different objects, and majority of the functionality comes from the parent. If some of those variations are needed in multiple classes (but not in *every* of them), then they belong into interfaces and become composition.
@bentomo
@bentomo 11 месяцев назад
I need "Change is the enemy of perfect design" on a poster above my monitor
@_nickthered
@_nickthered Месяц назад
I cannot satte how important single responsibilities principle and encapsulation are very important to avoiding common mistakes and misues of inheritance.
@not_ever
@not_ever Год назад
I clang-format on save with whatever defaults it considers the best. So because IDGAF enough to create a .clang-format file it does my braces on new lines. At first it would cause me geniune aggrievement but honestly you learn to accept it and move on. I work with C++, my life is shitty enough.
@derekpmoore
@derekpmoore 7 месяцев назад
Changes to the composed object can still force extensive refactoring of all the users of the composed object. Geez.
@Jabberwockybird
@Jabberwockybird 4 месяца назад
The point is that you can compose an entirly different object and leave the existing compsed objects alone.
@oblivion_2852
@oblivion_2852 Год назад
What do you think of query builders? I honestly can't stand query builders for sql. I'd rather look at a basic string with some replacement keywords or embedded variables.
@ThePrimeTimeagen
@ThePrimeTimeagen Год назад
they always seem so neet then... they become less neet
@oblivion_2852
@oblivion_2852 Год назад
@@ThePrimeTimeagen just... Why should I be learning a new structure/language with your query builder? If you just keep it as sql I can read it without having to figure out your custom representation of a query.
@HrHaakon
@HrHaakon Год назад
String replacement can take a long walk of a short pier, but SQL is better than 90% of everything else the SECOND you're no longer doing basic CRUD that's 1-1 with a single table with no joins.
@victorolvera6482
@victorolvera6482 Месяц назад
When implementing a compiler inheritance is elegantly straight forward. Functionality is presumed from the way objects are structured in memory. Where as composition there has to be an active mechanism in determining if such particular object contains a particular functionality. Maybe inheritance is a house of cards that may apart due to design issues. But when it works it should be more efficient then composition
@victorolvera6482
@victorolvera6482 Месяц назад
Inheritance is an O(0) solution where as composition is O(1) at best.
@naranyala_dev
@naranyala_dev Год назад
ok, let's react another high quality code video
@RyanTipps
@RyanTipps Год назад
in React, if you making heavily nested reusable "functional" components - they're effectively classes with multi layers of inheritance and you run into same problem of everything being too interwoven
@kellyrankin8844
@kellyrankin8844 Год назад
I always cringe deeply when I see inheritance being used in Angular
@floriansalihovic3697
@floriansalihovic3697 Год назад
There is so much to unpack there …
@DeepFriedOreoOffline
@DeepFriedOreoOffline 9 месяцев назад
This video so purely speaks to an idea I've been thinking about for a long time. I keep seeing these videos floating around about why OOP is a lie, and why it doesn't do what it was made to do. Which was solve the lack of modularity in imperative programming. To be fair, it doesn't solve that problem, we have modules now. However, this is exactly why OOP has evolved over time. It's not about trying to make infinitely reusable code snakes, it's about breaking down large frameworks into easily definable objects that can be instanced to serve a higher purpose.
@OffroadTreks
@OffroadTreks 5 месяцев назад
I subscribed to this channel the day he said "assestics" about the curly braces, lol
@Slashx92
@Slashx92 Год назад
I also made my first game with xna, a tower defense, and I also had like 4 levels of inheritance for only the attack effects lmao Oop obsesión was so bad when I was young
@ThePrimeTimeagen
@ThePrimeTimeagen Год назад
You have no idea how much I can relate to this
@oleksiistri8429
@oleksiistri8429 Месяц назад
I use classes mostly for packaging functions/logic into one thing, not for reusing, that way the code becomes simpler for me to read. BTW, I also use brackets as this guy does😂, to me it helps a lot to distinguish sections of code and helps the code to breath, thanks to surrounding space, which also adds up to readability
@toxicitysocks
@toxicitysocks 8 месяцев назад
Ok that rust thing is cool but I still love go’s implicit interfaces
@bonsairobo
@bonsairobo 11 месяцев назад
The XNA inheritance rant was gold. RIP XNA
@matyasrakosi3100
@matyasrakosi3100 Месяц назад
is the screen tearing part of Prime's video, or did my system fuck up again? it seems like every video he watches has tearing, but i don't see it in other videos i watch and it's driving me mad
@skeleton_craftGaming
@skeleton_craftGaming 9 месяцев назад
Isn't that [having your brackets on new lines] like from the Google style guide or some other document that has the same weight as that? What's the standard and a lot of IDEs
@yazalulloa
@yazalulloa Год назад
As someone that started in Android development and then transition to backend development in Java, DI is a godsent, I can't imagine myself not using it
@m4rt_
@m4rt_ Год назад
writing a game with an ECS (Bevy for Rust for example) is best.
@adambickford8720
@adambickford8720 Год назад
It's easier to add code than to change it. Only couple/abstract when you have to and w/the smallest possible 'surface area'.
@mskiptr
@mskiptr Год назад
Abstract when the abstraction is actually there. Preferably if you can prove it. And use interfaces, not subtyping
Далее
I spent six months rewriting everything in Rust
15:11
Просмотров 403 тыс.
Мы будем есть ЭТО через 100 лет?!
00:55
skibidi cat pedro 🐈🔥  #skibiditoilet
00:20
Просмотров 3,5 млн
Dear Functional Bros | Prime Reacts
26:03
Просмотров 188 тыс.
The Flaws of Inheritance
10:01
Просмотров 898 тыс.
Is Stack OverFlow Evil? | Prime Reacts
38:13
Просмотров 198 тыс.
Why I Quit Netflix
7:11
Просмотров 483 тыс.
Is clean code a LIE? Primeagen x Casey Muratori say so
14:15
1 TRILLION Messages on Discord | Prime Reacts
28:01
Просмотров 151 тыс.
Why You Should AVOID Linked Lists
14:12
Просмотров 269 тыс.
Serverless Was A Mistake | Prime Reacts
13:40
Просмотров 207 тыс.
2 Regrets From 55 Year Old Programmer
20:19
Просмотров 356 тыс.
APPLE совершила РЕВОЛЮЦИЮ!
0:39
Просмотров 360 тыс.
✅ЛУЧШИЕ фишки iOS 18🔥
0:51
Просмотров 92 тыс.