12 ms·
Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)
- King-Aaron 4y agoYou can add code to ducks, however the results may vary from your expectations
- gmac 4y agoI have found survey questions to be a good, practical example of the pleasures of OOP. See, for example, section 3.2 in https://www.econstor.eu/obitstream/10419/66819/1/717744094.pdf https://www.econstor.eu/obitstream/10419/66819/1/717744094.p...
- chriswarbo 4y agoI completely agree that "good design"/"bad design" depends on the problems we're trying to solve, rather than some abstract property of the entities involved (i.e. whether "Car" should extend "Vehicle" or not, and whether those classes should even exist, cannot be answered without knowing what we're trying to accomplish). The suggestion of GUI widgets is certainly better and more concrete; although it's skating dangerously close to "Circle extends Ellipse" and "Square extends Rectangle" territory! (e.g. https://softwareengineering.stackexchange.com/questions/238176/why-would-square-inheriting-from-rectangle-be-problematic-if-we-override-the-set https://softwareengineering.stackexchange.com/questions/2381... )
- joshka 4y agoMuch agreement on this. It's concrete, visible and has behaviors that work well (click, resize, draw etc.) as well as providing a good entry into the thought process when designing modern user interfaces with components.
- everyone 4y agoI'm a game dev and usually program in C#. I love C# and honestly some features of OO (like objects and classes) are great for programming games. But inheritance is just a shit feature imo. Situations where it would be beneficial are extremely rare. I generally just pretend it doesnt exist. There are much better alternatives to it for most situations (eg. composition, build a class from other smaller classes that do one thing)
- the_other 4y agoOnce you've ditched hierarchy, haven't you entered "functional programming" territory? It's just types, structs/maps/dictionaries, factories, and modules/closures now, right?
- fabian2k 4y agoYou still have classes, even if you ignore inheritance entirely. And e.g. with the built-in dependency injection in ASP.NET it feels like you're subtly encouraged to use composition for many cases. This is still very much OO-style programming, inheritance is only one part of this.
- rkangel 4y agoYou've still got the concept of data hiding and an object lifecycle, I think. You're right in functional programming we often operate in quite a similar way to "objects without inheritance" - your module has an internal data structure, creates it at some point, manipulates it through a series of module functions. of course in functional you are usually not usually mutating directly.
- everyone 4y agoThe atomic element of code is the function. If I just religiously stick the fundamentals of good programming, tiny functions, avoid coupling, avoid duplication (within reason), then I am at least half way to having nice maintainable code already. Once I have all these really nice tiny functions, Its trivial to reorganise and replace them. Though I find classes also very useful, a class is mainly a bucket that you put functions into. Ideally a class is a black box that does one thing. All the functions needed to do that thing are in the class and also any relevant fields. Not being able to have fields in there would be counter productive. It's just so handy to have all the functions + fields that govern this one element of your game all in one place.. When you need to make changes everything relevant is one place, and that place also functions as a black box that the other elements dont know about. So to change one feature in the game u just change or replace that one class. Just looking at the functions, nice maintainable code would look identical in a functional or OO language. I think the big differences between functional and OO are actually not important. I could put functions in a class, or just together in the same file. Putting certain functions and fields into this same bucket is just a convenience and its intuitive to understand imo. Like I said in 6 months time when I have to change feature X I know where to look.
- alangibson 4y ago> In good OO programming, we don’t make class hierarchies in order to satisfy our inner Linnaeus I wish someone had told me this when I first started coding. I wasted so much time building pointless hierarchies based on ontology rather than DRY.
- bborud 4y agoDRY is also not the goal.
- rkangel 4y agoIt's not a million miles from it though. If you start from DRY as an approach to OO design you'll produce something vaguely reasonable and be close enough to where you want to be that you can learn the differences.
- bborud 4y agoI should have been a bit more precise. There are essentialy two ways to approach DRY in OO. One is to inherit implementation, which isn't the best way to go about things since it leads to more brittle code. The other way is to make sensible use of polymorphism and composition. There are aspects of DRY that are worth pursuing (like reducing the number of places you need to get things right) and some that aren't worth pursuing (thinking you reduce the amount of work by re-using code heavily). For code to be reusable you have to be sure that developers only have to care about its interface. Implementation inheritance often doesn't do that. I've worked on projects with people who were obsessed with DRY and made heavy use of implementation inheritance, and the projects inevitably needed extra work to untangle a brittle mess with lots of surprising behaviors.
- rkangel 4y agoYes, to be fair the simplest advice to new programmers about how to use inheritance should be "don't". Aggregation good, polymorphism good, inheritance bad more often than not.
- scotty79 4y agoEntity-Component-System is so much nicer paradigm than any hierarchy. I wonder why it's not used much outside of gamedev.
- joshka 4y agoExplain "entity" to someone that is just starting their software development career ;)
- rje99 4y agoI would have agreed with this whole-heartedly when I first started using ECS. It has its own difficulties though.
- scotty79 4y agoLike what?
- 202206241203 4y agoThat's just structured procedural programming - subroutines mutating separately-defined data. This used to be all the rage before OOP took over!
- torginus 4y agoIt is - it's just called SQL and is considered the opposite of cool.
- scotty79 4y agoIt's kinda shame that people try to cram it into rigid object model instead embracing flexibility on the code side too.
- viktorcode 4y agoIt does not replace OOP because there are no answers to other questions like: does it support polymorphism? Or data encapsulation? Etc. It's a data access design principle, and that's about it.
- mikojan 4y agoIt's not OO tutorials, it's OO.
- DeathArrow 4y agoAfter many years of OOP, I'm not sure if we gained anything from OOP, and if it wasn't a solution in search for a problem. At first I was enthusiastic. Then I've realized that there might be better ways to solve problems than trying to fit everything in a "everything is an object" mentality. OOP can lead to overly complex code, uneeeded abstractions and design patterns thrown on top of each other for no good reason. There was a thinking that using objects you can model or imitate real life, but that is silly. And of course, programming doesn't deal with real life, but with bytes and instructions, data and actions performed on the data. I still use OOP because most of the industry demands it, but when I can, I try to use a data oriented and a bit of a functional approach, even if I am using an OOP language.
- 202206241203 4y agoOOP still rules the GUI. Even if you spread some functional sauce all over it.
- corrral 4y agoAs one can see in React, which contorted itself to be "functional" and ended up inventing bad, new syntax for objects in a language that already had objects built-in. They evidently couldn't figure out a better way to handle it, and landed on reinventing the wheel, badly, and but calling it something else.
- hellohowareu 4y agoEh, considering its popularity I suppose it is a "least bad" if one chooses a cynical yet realistic perspective. Personally, after working with vanilla JS, then jquery, I looked at angular and react. I liked react so much better
- mynameisash 4y agoI'm reminded of the "Object oriented programming is bad" series: https://youtu.be/QM1iUe6IofM https://youtu.be/QM1iUe6IofM
- bdg 4y agoI actually like to ask people in interviews to model a car and car factory because I want to see right away if they go deep into the nonsense of extending everything, or if they can use composition, or get away with something focused on maintainable code that meets requirements. I've seen it all. Prius extends Car extends vehicle extends motor extends ... Right within the first five minutes of the interview. But I also think these old "a bike extends a " tutorials were the most frustrating thing in the world and made no sense to me when I was trying to learn OOP in the first place. From my memory, I recall all the examples I could find were absolutely nonsense but blogs were full of posts with lots of non-real-world about connecting web requests things to a DB code and lots of "yeah it's just like a person is-a mammal which is-an animal which...". It wasn't until I wrote some c++ and looked at how it worked in the heap and stack before I started to understand it better. Then later I learnt about SOLID and discovered that you almost never really want to use extension in practice (at least in the problems I worked on), except for things like interfaces in places you expect (and plan to have, and even better if you already do have) a reason for variations in sub-types that have the same contract, or need to cross system boundaries. I almost always want to use composition. I will use extensions but this should be really specifically be selected for a few key points.
- quietbritishjim 4y agoThe problem with that is you might feel pressured to talk about Prius extends Car extends Vehicle etc. even if you wouldn't do that in real code because it seems the question is meant to probe the concept of inheritence so it's natural to answer that way. It takes a brave interview candidate to say "the best solution depends on the exact nature of the problem - and your problem doesn't make any sense so there's no valid solution".
- BoorishBears 4y agoI feel like you picked up on the wrong problem in their example... > Prius extends Car extends vehicle extends motor extends The problem isn't that it's too in-depth, or too overbuilt, that answer is as close to objectively wrong as you get on a pretty open ended question and I'd imagine only an extremely junior developer would come up with that. For example, you could maybe argue that a model of car extends a specific car. I'd expect an experienced developer to favor composition over inheritance at that stage, but that's open to debate. But if a Vehicle extends a motor, does a motor extend a piston? Does a wheel extend a lug nut? At that point you're moving away from "arguably correct" to just plain failing to answer the question. It shows they don't know the difference between composition and inheritance. > It takes a brave interview candidate to say "the best solution depends on the exact nature of the problem - and your problem doesn't make any sense so there's no valid solution". You're free to ask questions, we're supposed to be trying to collaborate. I don't think it's "brave" to instead say "your problem doesn't make sense". Shows more hubris than anything. How is it any different than a systems design question?
- bborud 4y agoThe book "Design Patterns: Elements of Reusable Object-Oriented Software" has an initial chapter that provides one of the most concise introductions to OO I've read. Its main focus is on polymorphism and it provides some easy to understand examples. In fact, if you think of Go as an OO language (which I guess many won't), it has all the things you actually care about from OO. It doesn't have inheritance and you don't explicitly declare that a type implements some interface (). Since there is no inheritance of implementation you are forced to use composition, which is what people tend to end up recommending after a few years of fighting with OO code that has been written by people in love with a Linnean hierarchies and complex approaches to DRY. () There are tricks to accomplish this, for instance creating a New() function that returns an interface type, which will make the compiler ensure you implement the interface).
- quietbritishjim 4y agoPerhaps this would work: Build a program that... * That has a hardcoded list of strings baked into it * Accepts as inputs a filename (but can be empty) and a substring to search for * At runtime, either (a) (if filename empty) iterates over hardcoded list of strings, or (b) opens file and iterates over lines in it * For each string / line, if contains search string then output to stdout (and maybe also increment a counter). It's very artificial but does allow the basic idea of OO to be illustrated and it's far less code than a GUI example. You have a base class and two derived classes that really do have a different mechanism, and even have different state (file handle or integer index). The program logic is also quite decoupled (the class interface is not tied to the fact you're doing string search). You could solve the problem without classes by reading the whole file into the same list structure as the hardcoded strings, but that aspect is actually quite nice because you can present that first and then ask what to do if you want to avoid that unnecessary memory usage. It's also nice that you're illustrating a really common OO pattern (iterator). The only slight downside is that some languages make this easy to do without (explicit) classes e.g. Python generator functions. But you can add a footnote that they exist and this is just to illustrate classes - it still beats the abstract examples.
- Joker_vD 4y agoRefactoring something along the lines of static void Main(string[] args) { var filename = args[0]; var needle = args[1]; var linesToProcess = filename != '' ? File.ReadAllLines(filename) : HardcodedLines; ProcessLines(linesToProcess, needle); } static void ProcesLines(string[] linesToProcess, string needle) { // lines-processing code... } into something like static void Main(string[] args) { var filename = args[0]; var needle = args[1]; var linesProvider = filename != '' ? FileLinesProvider(filename) : MemoryLinesProvider(HardcodedLines); ProcessLines(lineProvider, needle); } static void ProcesLines(ILinesProvider linesProvider, string needle) { var linesToProcess = linesProvider.GetLines(); // lines-processing code... } would still need some justification, IMO: what's the benefit of giving ILinesProvider to the ProcessLines instead of just string[]?
- deleted 4y ago
- snorkel 4y agoWhen I first learned OOP from the dry examples like Shape is the base class of Circle and Triangle, and so on … I just didn’t appreciate why that was much better than the flat imperative style of plain old C and retreated back to the comforts of C. Then I started writing larger C programs with structures that had common function pointers called “draw” and “rotate” and realized these are just obj ct methods … and the structures were different implementations of a common base class … OK, so I guess OOP is useful after all. So it helps to compare the old ways to the new ways side by side, with a real world example, to understand why the new ways are better.
- TomMasz 4y agoWhen you're introducing OOP to beginning programming students, these metaphors still have some value. Beyond that, though, it's time to go with more realistic examples of polymorphism.
- AutomatedChaos 4y agoNot sure why but this book came to mind: https://en.wikipedia.org/wiki/The_Island_of_Doctor_Moreau https://en.wikipedia.org/wiki/The_Island_of_Doctor_Moreau "You can’t fake the ability to turn a duck into a penguin by moving its duckness into an animal of some other species that can be replaced at runtime."
- substation13 4y agoThe OOP community fascinates me. It's clear that OOP in the sense of "Car extends Vehicle" is not a good idea, yet the classic OOP languages go out of their way to support this kind of programming. Meanwhile the alternative approaches require you to jump through a bunch of hoops or apply convoluted "design patterns". Writing good, modern "OOP" you are often fighting the OOP language! Things are getting somewhat better (e.g. Java Record types) but perhaps it is time to admit these languages just aren't a good fit?
- fabian2k 4y agoThe only real difference is that inheritance as explicit language support while composition is something you can easily implement with common language features. It's not really more difficult to use composition than inheritance. As an example, if I want to use composition in C# using ASP.NET, I simply inject the class I want to use into my new class using the built-in DI. This is as simple as extending the class.
- substation13 4y agoSome features are plain missing (or must be implemented in a convoluted manner): - Discriminated unions - Immutable data types (records) - Free functions (or modules of free functions) - Software transactional memory (STM), atoms - Ad-hoc polymorphism (traits) - Custom operators (used sparingly for building DSLs) - List comprehensions Instead we get anti-features like automatic properties, implementation inheritance, events, object initializers, etc...
- tester756 4y ago>(records) there are >- List comprehensions Enumerable.Range? >- Custom operators (used sparingly for building DSLs) Could you please show what kind of DSL you'd want to write?
- substation13 4y ago>(records) Agreed, although this a recent addition in Java and a step away from old school OOP >- List comprehensions Enumerable.Range is not equivalent to list comprehensions. For example, in F# you can build a list using a comprehension containing more or less any code you like. It's incredibly powerful for things like building HTML. >- Custom operators (used sparingly for building DSLs) These are used in many places, but to give one example https://www.cs.tufts.edu/~nr/cs257/archive/simon-peyton-jones/contracts.pdf https://www.cs.tufts.edu/~nr/cs257/archive/simon-peyton-jone...
- bottled_poe 4y agoDidn’t read the article, but based solely on the title, I assume it’s a straw man. I.e. declare that vehicle is a sensible abstraction for our needs, then show why it isn’t.
- d--b 4y agoIf I had to state a law about how to do OOP correctly it would be: - A base class and its implementation(s) must never be written by the same person. Obviously a bit of a strong opinion, but inheritance should delimit layers of abstraction, technically separating the responsibility of developers.
- bluGill 4y agoA base class should only exist where there are implementations -it needs to be plural. Otherwise just fold the base into the child, or better yet use composition not inheritance. I generally do not count any form of test double (mock...) as a an implementation, since only rarely is the real implementation something that you should mock.
- skitter 4y ago> Penguins don’t implement the “fly” method that can be found in birds. Yep. That would be like having immutable lists which implement List which has an "add" method. Obviously that would be too stupid for a sensible programming language.
- cloogshicer 4y agoDoes anybody have some actual good examples for teaching inheritance to beginners? I've thought about this for quite some time and couldn't come up with anything that strikes a nice balance between simple and actually useful.
- dls2016 4y agoAny sort of plugin architecture, e.g. VST audio plugins. Often there's an interface which you could implement directly, or you could inherit from an abstract class which provides some common functionality. I like this because it stresses that deep hierarchies aren't necessary to be useful. Also, if you're refactoring and see a "switch on type" then a little bit of inheritance is probably OK. I admit I taught intro to C++ and used shapes as an example. I spent a few weeks building a little "ASCII render" thingy with a 80x30 "canvas" where each character is a pixel. Then you could place Shapes on the canvas and the shape would decide whether a given pixel was contained() inside of it. I remember my first OO class where the car analogy was proven to be bad using the existence of the El Camino.
- cloogshicer 4y agoThanks for your suggestion!
- kabdib 4y agoI spent a LOT of time in the late 80s and the 90s wrestling with class hierarchies, coming up with one tower of abstraction after another. So much wasted time; perhaps it didn't help that my vehicles were C++ and Java, but I think that I would have fared just as well in any other OOPy language. What I got as a side-effect was a bunch of re-written code. And I wondered: Maybe OOP is a terrible paradigm. Maybe the designs that come out of it are so awful that it causes people to rewrite code, over and over. Re-examined systems are often better than first attempts. Once you reimplement something five or six times, you've probably explored most of the problem space and are pretty good at it. It's even likely that you are thoroughly sick of the project and just want to get the stupid thing done and shipped. (Yeah, your PMs and entire management chain just smiled behind your back). In other words, it's Brook's "plan to throw one away, you will anyway" in action, while telling your boss that you had to rewrite your framework again because it didn't handle the flightless, swimming bird scenarios.
- skadamat 4y agoObject oriented programming was meant to be used in a Smalltalk environment, where immediacy & liveliness were key principles of the design. OOP wasn't meant to be used by professional programmers ever, but this is always always forgotten. Why do we still talk about OOP when it comes to professional / full-time programming? OOP was always meant to be about providing end-users a way to create programs & dynamic behavior without becoming full-time programmers. - http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/doc_kay_oop_en http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/doc_kay... - https://wiki.c2.com/?AlanKaysDefinitionOfObjectOriented https://wiki.c2.com/?AlanKaysDefinitionOfObjectOriented
- pbourke 4y agoI don’t get this originalist argument. After it’s introduction, OOP very clearly evolved in a professional direction almost immediately. Why would you erase that history, and the work of hundreds to thousands of people working on object technologies, because it wasn’t the original conception?
- skadamat 4y agoFair point! I guess when I see people saying "OOP isn't getting us what we want" ... then I want to point out that it was adopted for a different use case for which people are claiming it's falling short for?
- nuc1e0n 4y agoBut OOP was specifically created to model real world objects and their relationships. If this article is saying OOP doesn't do that very well and we should not think in those terms, what's it good for?
- Ensorceled 4y agoAs someone who has been using OOP since C++ was Cfront and you fetched it from usenet ... I find these conversations fascinating. It's like listening to a conversation about cars where someone says they hate cars because you have to figure out a manual choke and the many inner tube failures. Do people still use these crazy inheritance trees? I haven't encountered it since the early 2000's.
- aidenn0 4y agoFrom an outsider's perspective, they do seem to still be popular in Java land.
- jansan 4y agoDoes this count? EventTarget -> Node -> Element -> SVGElement -> SVGGraphicsElement -> SVGTextContentElement -> SVGTextPositioningElement -> SVGTSpanElement And the whole tree could be described as "crazy", but it does actually make sense.
- acidburnNSA 4y agoI do scientific modeling. We have classes and hierarchies of different physical components we simulate, like fuel assemblies and pumps and heat exchangers. I guess this falls into the exception of "clone of The Sims or something" so perhaps my complaint is covered.
- helmholtz 4y agoYep, me too. I guess most programmers dont know what modelica is or does.
- layer8 4y agoThe problem is “A extends B”. You want to teach “A implements B” first. The important idea is that there’s a protocol/interface for which there can be different implementations used in parallel at runtime, and the interface type allows the client code to abstract from the different implementations. The next step is that an implementation may implement multiple interfaces at once, which also may be subinterfaces of one another. Only as a last step you can introduce implementation inheritance, which is just an optimization (both in runtime mechanism and code verbosity) when reusing code, an optimization which comes at a cost regarding maintenance and implementation dependencies.
- dymk 4y agoI disagree with the article, which talks about building a holistic understanding when learning, and then ironically misses the forest for the trees regarding programming metaphors. The author is obviously an experienced programmer, so I suspect they've forgotten what the mindset of an absolute novice is like, and to start programming with zero prior exposure to the concepts. For the novice being introduced OOP, the `Duck / Cat / Dog <: Animal` analogy is useful to demonstrate how things like inheriting methods and sharing behavior works. It helps one start to think in terms of hierarchies and the boundaries between "concepts" in code. Obviously, in 'real' code, you won't be writing much that involves a literal hierarchy of animal species. That's not the point. A beginner knows what a dog and a duck and a cat are in the real world. The "a-ha!" moment is mapping real-world relationships into a brand new abstract environment called Object Oriented Programming. When you've never written a line of code in your life, abstract things like "network protocols" and "file I/O" and "ImageDisplay" (which is neither an image nor a display) are confusing, and so frustrating, and so not useful for teaching a complete novice.
- redisman 4y agoI disagree. Teaching people to think about abstractions wrong is not in any way helpful. Everyone I know including myself had to spend years writing bad code before realizing that this way of thinking is counterproductive. It reminds me of this quote from Kung Pow Don’t worry about Wimp Lo, he’s an idiot. We’ve purposefully taught him wrong… as a joke. Composition is an infinitely better method to teach if you have to teach OOP. That way you don’t need to unlearn what you thought was the right way but is actually useless at modeling almost anything.
- JoshCole 4y agoAbstractions are useful because they simplify and if you don't allow error you don't allow maximization of simplification. You can formally relate this to learning problem formulation complexity. When you do you encounter things like branching factors which effect solution times which lead to natural results like fast but finishes being better than optimal but never terminates. This can hold even despite error in the abstraction and there are techniques for recovering that error at runtime because a particular problem is a less general and more specific situation and so isn't as cursed by branching factor. Edit: A previous version of this comment was more wordy in stating this and mentioned that there are formal proofs to this effect.
- legulere 4y agoThe problem with all those examples is that they are specializations, but that's not really how inheritance works in OOP languages and more resembles refinement types. A square is a rectangle with the condition, that both sides have the same length. Inheritance in OOP languages is used to either for interfaces, or for tacking on data and maybe functionality because you are too lazy to implement out composition instead.
- bighuh 4y ago> We make class hierarchies in order to simplify the code by allowing different parts of it to be changed independently of each other, and to eliminate duplication (which comes to the same thing). Yeah. Exactly. Which is why Dog extends Animal. It has a set of common features (code/behaviors, and data like number of legs, amount of fur, and so on). It is a really good analogy and a really good point to give someone an idea of why you would use inheritance. It requires absolutely no programming knowledge, and best of all, it's not difficult to imagine cases where you might actually use it. c.f. basically any game with dogs in it where they're a subclass of NPCs. And the same for Car extends Vehicle. A vehicle can have any number of wheels and any number of doors. A car can have any number of doors but it always has 4 wheels. All cars move in approximately the same way, while vehicles can articulate or skid-steer or ... Just because something is simplified does not mean it has no value. And just because *you* would not use these designs in *your* life does not mean others wouldn't. As TFA says: "unless they are talking about writing a clone of The Sims".
- jzwinck 4y agoHere are a car and a motorcycle each with three wheels: https://en.m.wikipedia.org/wiki/Reliant_Robin https://en.m.wikipedia.org/wiki/Reliant_Robin https://en.m.wikipedia.org/wiki/Piaggio_MP3 https://en.m.wikipedia.org/wiki/Piaggio_MP3 What shall we do with them in our class hierarchy?
- lelandbatey 4y ago> A vehicle can have any number of wheels and any number of doors. Does that mean zero doors and zero wheels? Because a jet ski is surely a vehicle, right, and it has zero wheels and zero doors. Likewise, what about a cable car (aerial lift)? It has doors (maybe), but probably not an internal engine. It's definitely a vehicle, but it has almost nothing that's similar about it compared to the car (automobile) you described earlier. If it where a class, the "vehicle class" could really only meaningfully have some attributes related to transport (like human/cargo capacity) and some methods around movement in the most general sense. If we keep breaking this down, we'll find a huge taxonomical network, a vast sea of interlocking Venn-diagrams of attributes and capabilities. This is the corner that those OOP tutorials force people into: trying to turn a network into a tree, and it doesn't ever really work (at least not without awkward compromises). Sure, for a beginner who's never grappled with trying to map concepts to things, this can be a nice contained way to start. Eventually though, that beginner will need to learn some the next levels of more general thinking; e.g. one where they can start modeling interfaces/protocols and their relationships.
- nmilo 4y agoObviously modelling your program like Car extends Vehicle is bad, but thinking in terms of real-life relations makes thinking about complex subtyping relations like covariance much easier to grasp. Compare: > If B and C are subtypes of A, then List<T> must be invariant over T since List<B> should not be a subtype of List<A>, which can contain both B and C. with: > List<Cat> can't become List<Animal>, because you might add Dogs to that list!
- mackman 4y agoLong ago in the games industry I was applying for a position at a studio. Didn't end up getting a job but a friend did. A few months later he was bemoaning their terrible code base which included a car class that inherited from wheel four times.
- hikarudo 4y ago"A car is a wheel, and is a wheel, and is a wheel, and is a wheel".
- dang 4y agoRelated: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011) - https://news.ycombinator.com/item?id=21298341 https://news.ycombinator.com/item?id=21298341 - Oct 2019 (101 comments) Goodbye, shitty "Car extends Vehicle" object-orientation tutorial - https://news.ycombinator.com/item?id=2914405 https://news.ycombinator.com/item?id=2914405 - Aug 2011 (128 comments)
- jacobsenscott 4y agoOOP != class hierarchies. Unfortunately when the industry shifted from procedural programming to OO they chose C++ and Java. These languages are mostly procedural languages with classes bolted on. They pretty much forced you to write hierarchies - it was the only way to get the good parts of OO - loose coupling, polymorphism, inversion of control, etc. Since inheritance was the only tool in the toolbox industry programmers naturally were driven to try and leverage inheritance for everything even though it is the worst part of OO. Modern multi-paradigm langues do a much better job of letting you use OO when OO works, functional when functional works, etc. You should use the tool that works when it works. I do plenty of functional and OO programming in ruby, declarative programming in SQL, mostly functional style in JS. There are plenty of places where each one works great.