17 ms·
The faster you unlearn OOP, the better for you and your software
- adnzzzzZ 8y ago>The vast majority of essential code is not operating on just one object – it is actually implementing cross-cutting concerns. Example: when class Player hits() a class Monster, where exactly do we modify data? Monster's hp has to decrease by Player's attackPower, Player's xps increase by Monster's level if Monster got killed. Does it happen in Player.hits(Monster m) or Monster.isHitBy(Player p). What if there's a class Weapon involved? Do we pass it as an argument to isHitBy or does Player has a currentWeapon() getter? As an indie dev this is something that I struggled with early on and my solution so far has been to choose the most obvious place where all those things should happen and just do it there (in this case it would be on the Player, in other less obvious cases it gets more fuzzy). What does the non-OOP solution for this problem look like?
- jdub 8y agoEntity-Component-System, amusingly explained in this great talk from RustConf. https://www.youtube.com/watch?v=aKLntZcp27M https://www.youtube.com/watch?v=aKLntZcp27M
- adnzzzzZ 8y agoThat solution is more burdensome than OOP
- Epskampie 8y agoDiagree. Unity works like this, and it’s great for attaching multiple behaviours to an object (i.e. a Player can be Hit, but an Enemy as well). It saves you having to make up a inheritence hierarchy that never seems to work out (Player extends Hittable or something? But it also needa these 10 other behaviours...)
- coldtea 8y agoNot at all. It also has excellent visibility, extensibility, and debugabillity.
- jcelerier 8y agobut... all ECS systems use classes or equivalent at some point
- coldtea 8y agoIf the classes are shallow that's fine. The problem is using classes to model the whole behavior, not using them to hold some values together.
- krapht 8y agoIt looks like a bunch of flat, 2d tables like you might find in a spreadsheet or database.
- geocar 8y ago> What does the non-OOP solution for this problem look like? function hit(player, weapon, monster) { This is a major problem with single dispatch, a popular OOP implementation choice, but not the only one. Common Lisp and C++ have multiple dispatch, which is a generally accepted solution to this problem. It seems like a lot of the challenges you're facing has to do with object-oriented design not being a good fit for your problem. Some problems really do organise well into independent actors, maybe the one you're doing isn't one of them?
- vnorilo 8y agoI don't think C++ has a dynamic multiple dispatch mechanism. You can craft one with the visitor pattern or some precompiling or macro sheanigans. I'd love to hear about the best way of doing it.
- geocar 8y agoNo. Not dynamic. The best way is to use Common Lisp. I don't know if there's consensus for other, lesser solutions. Stroustrup seems to think C++ just isn't good enough[1], but good ol' function overloading is good enough for the cases we're discussing. [1]: http://www.stroustrup.com/multimethods.pdf http://www.stroustrup.com/multimethods.pdf
- deleted 8y ago[deleted]
- geowwy 8y ago> when class Player hits() a class Monster, where exactly do we modify data? Monster's hp has to decrease by Player's attackPower, Player's xps increase by Monster's level if Monster got killed. Does it happen in Player.hits(Monster m) or Monster.isHitBy(Player p). What if there's a class Weapon involved? Do we pass it as an argument to isHitBy or does Player has a currentWeapon() getter? I don't see how this is a problem unless you think programming objects correspond with physical objects. My first thought is make a separate Swing class representing the player swinging their weapon. There's probably an even better way to do it but this gets around the issues mentioned above. class Player { fun takeSwing { swing = new Swing( this.currentWeapon, this.location.offset(this.direction) ) if swing.killedMonster { this.xp += swing.monster.level } } } class Swing { fun new(weapon, location) { this.weapon = weapon this.monster = findMonster(location) if this.monster != null { this.monster.takeHit(this) } this.killedMonster = this.monster != null && this.monster.dead } fun damage { return this.weapon.baseDamage + this.weapon.bonusDamage } } class Monster { fun takeHit(swing) { this.hp -= swing.damage - this.defence if this.hp <= 1 { this.die } } }
- coldtea 8y ago>I don't see how this is a problem unless you think programming objects correspond with physical objects. This is a problem because we don't just want "any old design that sorta kinda works" but a guiding principle to our design, and to find the optimal place for each action/data.
- segmondy 8y agoGood example, I think that's why people struggle with OOP, they do think that "programming objects correspond with physical objects". This is the same reason they struggle with storing states in databases because they try to map OOP to tables.
- eitland 8y agoI read this quickly to see if this was the piece that should convince me. It was not. It is, IMO, a collection of strawmen. People have abused OOP? Yes. But - citing FizzBuzz Enterprise Edition (which is really funny even for us Java/.Net developers because it is so horribly wrong) or writing this - Because OOP requires scattering everything across many, many tiny encapsulated objects, the number of references to these objects explodes as well. OOP requires passing long lists of arguments everywhere or holding references to related objects directly to shortcut it. again IMO, demonstrate that the author never really understood OOP. What probably is true however is that a lot of people should unlearn the OOP they learned in school.
- bvrmn 8y ago> What probably is true however is that a lot of people should unlearn the OOP they learned in school. Can you provide references for proper OOP?
- hoorayimhelping 8y agohttps://en.wikipedia.org/wiki/SOLID https://en.wikipedia.org/wiki/SOLID I wish they would have taught me this in school. Instead, I learned that a cat is an animal, and a car has wheels, and a car is a vehicle. But not what any of these things have to do with one another and how to actually use them.
- bvrmn 8y agoI saw many SOLID code bases hard to grasp and maintain because implementation hides data flow. The most evil workers are [D]-purists.
- deleted 8y ago[deleted]
- abernard1 8y agoSOLID still doesn't accomplish what the author is criticizing in my opinion. If I have a SOLID codebase, how do I unroll the object graph to get, say, a hydrated JSON representation of that? (this is the data focus the author is talking about). I think a person who has maintained an ORM like Hibernate or Rails and wants a simple data projection without having to use their specific tools to do so implicitly understands this pain. A data oriented approach where records are passed through to the business logic as necessary doesn't have this problem. SOLID still has things like "cat.drivesIn(car)", and so even if the concretions are supposedly hidden behind an abstraction of that interface, the coupling is right there: "drivesIn" irrevocably binds a cat and a car together. In a data oriented, more functional approach, there is a function which happens to know something about cats and cars, and it pulls in two separate records to do its work. This is more of an a la carte approach to building relationships, whereas SOLID makes every consumer potentially need to worry about that because the coupling is in the contract.
- lispm 8y agoSome things never die. comp.object on usenet (15+ years ago) had a regular 'guest' explaining why table-oriented programming is better than OOP: http://www.oocities.org/tablizer/top.htm http://www.oocities.org/tablizer/top.htm
- dredmorbius 8y agoWow, that brings back memories....
- antialias 8y agoIn the context of creating a formal model for decision-making, yes table-oriented design can be a superior choice. https://www.hillelwayne.com/post/decision-tables/ https://www.hillelwayne.com/post/decision-tables/
- deleted 8y ago[deleted]
- hliyan 8y agoThis has been shared on HN many years ago, but I'm linking again in case there are younger engineers who might be unaware of this classic rant: Execution in the Kingdom of Nouns : https://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html https://steve-yegge.blogspot.com/2006/03/execution-in-kingdo...
- nyc111 8y agoThat was great. I read it for the first time. Similar scenarios happen in so many other fields. Some bad idea takes hold. Then schools teach it. Then more people invest time learning it so that they cannot admit it is bad and this goes spreading like wildfire and become sacred...
- hliyan 8y agoAnd then someone discovers that the old way was better and gives it a new name. When I was in school, functional programming was called "programming".
- _old_dude_ 8y agoJava type system is nominal not structural. While this rant rung a bell at that time, i've always found that this rant was too easy. Java had non public class, annonymous class and import static at that time. Nowadays, the Javaland has steal lambda and var from Scala, moving away from a real kingdom of nouns (partially, you still need those pesky functional interfaces).
- thanatropism 8y agoI'm a simple man. I don't have an advanced education in computer science (I did have a SICP-inspired first course in programming as an undergrad and an algorithms course in grad school using Dasgupta and Kleinberg/Tardos). Like everyone who's doing stuff with data, I live in Python now. I'm fairly conversant in functional idioms (wrote a monad tutorial when it was all the fashion), but like objects because they're a straightforward way to keep data and code together in a bundle that can be passed around and serialized. The typical situation for me is machine learning - I could have "fit_to_data" functions that return matrices or otherwise sum/product types (as they called it in Haskell) containing the estimated parameters and "predict_from_param_struct" functions, but having the whole thing in a bundle erases the whole problem of having to remember a weight matrix comes from a logistic classifier and not a linear regressor. That, or use an idiom like data LogisticParams a = LogisticP (Matrix a) (I don't remember Haskell syntax anymore) but I'm not sure how I'm better served by that. The scikit-learn-type idiom where every regressor is expected to have .predict and .fit methods helps me build new regressors while reutilizing all of the scikit-learn cross-validation/hyperparameter search tooling. The idiom above would require me to study the hierarchy of types upwards and whatever advanced features of the language they're using; but even if the scikit-learn team is using features of Python outside my understanding (say, async, or low-level numpy/communication with C libraries) I'm still able to adhere to a convention. --- That said, have y'all ever heard of Formal Concept Analysis [1]? It seems to me that a lot of the malaise about OOP is that tutorials and examples and maybe even production code (what the hell do I know) are struggling to define ad hoc concept hierarchies -- is it Kitchen.Lights.off() or Lights.off("kitchen")? What scikit-learn (and the universe around it that tries to adhere to the dialect) is simply to embed data (parameters which are derived from data) in code that knows how to use it. No one's trying to decide how TopologicalSpace.MeasurableSpace fits with IntegrableFunctions.ProbabilityMeasures... [1] https://www.researchgate.net/publication/275540145_Formal_Concept_Analysis_-_Overview_and_Applications https://www.researchgate.net/publication/275540145_Formal_Co...
- agumonkey 8y agoThe problem with OOP is that it became so ubiquitous. Everything had to be OO, millions of hours spent trying to fit everything inside absurd taxonomies. There's good bits in OO. You can find articles about how parameterizing large `switch` statements into objects can lead to obvious improvements. My only conclusion is to bet on biodiversity~. I learned so much in relational (db) logic, functional programming, logic programming, stack languages (forth threaded code) etc etc. As soon as your brain sense something useless discard it and find another cool trick/theorem to grok.
- partycoder 8y agoBashing imperative + structured + OOP is valid if you have a viable alternative. That viable alternative is proper namespacing, modularity and functional programming. If your alternative is another form of spaghetti your problem is not OOP. Your problem is the way you build abstractions. If your procedures and functions, the foundation of your program, are poorly thought, then you laid a shitty foundation for everything that follows.
- dnautics 8y agoShould be pointed out that this refers to C++/Java/Ruby/python style objects, and not smalltalk/erlang style objects, which is a message passing model for data storage.
- totemizer 8y agoAnd you do the first thing this author describes: http://www.smashcompany.com/technology/object-oriented-programming-is-an-expensive-disaster-which-must-end http://www.smashcompany.com/technology/object-oriented-progr...
- dnautics 8y agoNot really. Almost no one would call erlang or elixir an Oop language, but one basically does everything using Kay's style. No true Scotsman doesn't apply when the original definition legitimately shifts
- mbell 8y agoRuby has smalltalk style objects.
- snazz 8y agoCould someone enlighten me as to how Java style OOP differs from Smalltalk's variant? I've read the Alan Kay quote on how he's sorry for focusing on objects instead of message passing but I'm still unsure on how Smalltalk is so much better not having used it.
- dnautics 8y agoI can't speak for smalltalk but the actor model in erlang (but especially in elixir) is a joy.
- timbit42 8y agoThis may not answer your question and may not be 100% correct. Message passing means that objects have their own data and do not have shared access to it. This makes multi-threading and parallelized code very easy to do because you don't have to worry about data changing unexpectedly. Clojure, and other languages, achieve this by making data immutable, which has a similar effect. As you mentioned, after Alan Kay used the term "object-oriented" to describe Smalltalk, people focused on the objects instead of the messages and created languages designed around the idea of being object-oriented instead of around message passing (I believe Objective-C and Ruby do message passing), thereby missing the benefit. All OOPLs not based on message passing should die. Also, unlike Java, Smalltalk has no classes. Any existing object can be used as a template to create a new object.
- sunseb 8y agoYeah I agree so much. OOP is good when you are in school and you a have perfect use case like Vehicule, Car, Bicycle, but when you work on something else, you end up with abstract, absurd and bloated objects. OOP is only profitable for IT consultants, because they can sell books and bill many hours working on this mess.
- jryan49 8y ago> The vast majority of essential code is not operating on just one object – it is actually implementing cross-cutting concerns. Example: when class Player hits() a class Monster, where exactly do we modify data? Monster's hp has to decrease by Player's attackPower, Player's xps increase by Monster's level if Monster got killed. Does it happen in Player.hits(Monster m) or Monster.isHitBy(Player p). What if there's a class Weapon involved? Do we pass it as an argument to isHitBy or does Player has a currentWeapon() getter? Not saying this is the right way to do things but, if you're actually going to go 100% OO on something: Player.hits(Monster) returns Hit Hit takes a Player and a Monster in constructor, and has with(Weapon) You end up with: Player.hits(Monster).with(Weapon) Then Hit reaches into said objects and deals with changing the HP, and XP. You then have encapsulated the details in the actual Hit itself, which seems correct. It does read kind of nicely IMO...
- deleted 8y ago[deleted]
- jstimpfle 8y ago> It does read kind of nicely IMO... And this one line is why you're willing to setup all these crap boilerplate supporter classes and take a huge hit in runtime performance?
- jryan49 8y agoA lot of languages are made for this kind of interaction and can inline stuff hopefully, but that's the job for the VM or compiler. I didn't say it was the "right" way to do it. Also programming is the art of tradeoffs. If this does actually give bad performance, maybe it's a trade off the programmer is willing to make. Just like the article started off with "I don't think there's a silver bullet". OOP is a tool just like any other with pluses, and minuses. Also the Hit class may be a Singleton and only instantiated once.
- jcelerier 8y ago> And this one line is why you're willing to setup all these crap boilerplate supporter classes and take a huge hit in runtime performance? at least in C++, why would they ? it'll all gets inlined and you can do it so that there isn't any memory allocations if you know all of your cases at compile time (of course most of the time you want to be able to add new weapons, behaviours, etc, at runtime but in game engines you generally use scripting languages for this anyways).
- crazygringo 8y agoA lot of these initial points I don't think are relevant -- you can model your data in objects, data structures are complex because business needs are complex, data models wind up having implicit graph dependencies as well... BUT, "cross-cutting concerns" is where I think the main valid argument is. In my experience, OOP is just way too restrictive of a model, by forcing you to shoehorn data and code into an object hierarchy that doesn't reflect the meaning of what's going on. So I totally agree with the conclusion: just store your data in "dumb" arrays with hash tables or database tables with indices... be extremely rigorous about defining possible states... and then organize your functions themselves clearly with whatever means are at your disposal (files, folders, packages, namespaces, prefixes, arrays, or even data-free objects -- it all depends on what your language does/n't support).
- gerbilly 8y ago>In my experience, OOP is just way too restrictive of a model... Maybe, but if it's cross cutting concerns that bother you, just combine OOP with an aspect oriented programming library.
- coolaliasbro 8y agoExactly! So long as the developer approaches the solution with the expectation of scaling and extensibility from the get, this should not be a problem.
- Michaelanjello 8y agoI completely agree. For a DataStore in Python, I may often use a Pandas DataFrame or such. For random label-based access it can have an index too. Unfortunately, when asked to design an OOP architecture in a job interview, if you don't adhere to its religious enterprisy notions, you can risk failing the interview.
- DanielBMarkham 8y agoThere's something very important here. It also tends to be overstated. As a former OOP guy, I struggle with explaining what's going on with people that don't see it yet. Perhaps beginning with praise might work best. OOA as a group analysis tool is probably one of the most powerful things coming out of computer science in the past 50 years. Oddly enough, nobody does it much. Many if the problems this author brings up with OOP actually work for the best in OOA. It's not all bad. But there are problems with where we are. Big problems. We need to understand them.
- ced 8y agoI've never liked classical OOP much, but multiple dispatch is a lovely paradigm. One doesn't define _classes_ per se, but rather just plain old boring structs. struct Player xp::Int end struct Monster hp::Int end function hit(p::Player, m::Monster) p.xp += 10 m.hp -= 20 end The nicest thing is how one one doesn't need inheritance to "add a method" to an object. One just defines my_function(s::String) to be whatever, and it doesn't interfere with anyone else's code.
- donatj 8y agoRoughly that exact design but with classes was my instant thought.
- jcelerier 8y ago> One doesn't define _classes_ per se, but rather just plain old boring structs. in which language are there differences between classes and structs ?
- stevelosh 8y agoCommon Lisp http://www.lispworks.com/documentation/lw70/CLHS/Body/m_defstr.htm http://www.lispworks.com/documentation/lw70/CLHS/Body/m_defs... http://clhs.lisp.se/Body/m_defcla.htm http://clhs.lisp.se/Body/m_defcla.htm
- ygra 8y agoOf the languages i know, C++ and C# come to mind. Granted, in C++ the differences are fairly minor and inconsequential at runtime.
- wffurr 8y ago"struct" here is meant in the same sense that the author of the post refers to "PoD objects". Just data in public fields. Whereas a "class" is usually thought of as private data exposed only through methods. There is no language that enforces this distinction; it's purely by convention. C++ makes it a little simpler by having a different default access level. In any case, you are being needlessly pedantic and missing the point.
- kapauldo 8y agoLove oop
- vnorilo 8y agoI find that I generally agree. However, I have the intuition that good data-oriented design requires an exceptionally solid understanding of the problem domain. You might say that any good design requires that. I'm not going to disagree. But if there's a place for OOP, maybe it is as a preliminary abstraction, something to hold the chaos at bay while we build our understanding of the task at hand. Of course, preliminary abstraction has a nasty habit of becoming permanent.
- LaserToy 8y agoGive a man enough rope and he’ll hang himself.
- mabbo 8y agoI'm always confused when people criticize OOP, because most of the time the criticisms they use are just plain bad programming. Or they're using hyperbole that isn't really useful. You want to know why OOP is useful and common? Because it's easy. Easy things allow for faster development, faster onboarding of devs. Humans need a mental models of things and OOP very explicitly gives it. But like most easy things, OOP still works well enough even when it's done badly. That's not a bad thing. Working software beats non-working software. We shouldn't be telling people "stop using OOP! It's only for idiots!". OOP will be here forever. We should be teaching people how to do OOP right, what the pitfalls are that lead to bad design, and how to take badly designed OOP and fix it.
- chx 8y ago> You want to know why OOP is useful and common? Because it's easy. With as much proof as you have given, let me offer you a counterargument: it is common because academia loves OOP. It's easy to teach, it's easy to test. It is most decidedly not easy and very often not useful. My favorite example of how everything falls apart in due time is the color of a car. That's it, right? A car has a color. A Porsche Panamera might be a "carbon grey metallic" and it's stunning, but that's just one color still. Aye, up until the Mini Cooper tells you they need two colors. This world doesn't fit the OOP straightjacket. Your programming course does but the real world doesn't and when it doesn't then pain follows.
- devocracy 8y agoRefactor, with the right IDE this should take minutes. OOP witbout something like intellij or VS.NET is not fun.
- kangoo1707 8y agoWhat does OOP has anything to do with your IDE. I think you are referring to typings
- deleted 8y ago[deleted]
- jryan49 8y ago> Encouraging complexity Picking a satire piece on how something can be abused is not a great argument of "this thing is bad". For example, I'd argue anything written in an OOP language is going to be more readable than this (from the obfuscated C contest) https://www.ioccc.org/2018/algmyr/prog.c https://www.ioccc.org/2018/algmyr/prog.c Also, complex systems tend to benefit from OOP because complex systems can have multiple combinations of behaviors. Something IMO OOP is useful for.
- Const-me 8y agoOOP is not a silver bullet but for some classes of problems it's the best tool available. That's the reason why all good rich GUI frameworks are OOP-based, including HTML DOM we use on the web. GPU APIs, OS kernel APIs are OOP-based as well.
- mercer 8y agoI don't necessarily disagree, but wouldn't you agree that libraries like React seem to pull GUI's toward a more FP approach?
- Const-me 8y agoThis react? https://reactjs.org/ https://reactjs.org/ Their web site says following: > Component-Based > Build encapsulated components that manage their own state, then compose them to make complex UIs. Wouldn't you agree that components managing their own state is a textbook definition of OOP? They even have inheritance-based examples on their main page: > class HelloMessage extends React.Component
- mercer 8y agoYeah, that's a fair point. React isn't purely functional, but in practice I'd say it still leans heavily toward a functional approach You're encouraged to keep state only in top-level components, or in a functional-style state management library like Redux, and pass the data as props/parameters to pure components that are just functions. There's a huge emphasis on immutable data, and composing your various components/functions, passing them as props, etc. The fact that React switched to using classes makes it seem less functional than it is, and honestly I'm not entirely sure why they decided to do so. Anyways, you're not wrong, but the point I was trying to make is that React is definitely much more functional than other/older approaches to GUIs, and is popular in (large?) part because of that difference in approach.
- Const-me 8y ago> You're encouraged to keep state only in top-level components Doesn't state grow unmanageably large for complex GUIs? > React is definitely much more functional than other/older approaches to GUIs I'm not sure about that. Take a look, both projects are much older: https://github.com/dotnet/reactive https://github.com/dotnet/reactive https://reactiveui.net/ https://reactiveui.net/
- corebit 8y ago> Data is more important than code Nope. Right there at the beginning is where the author goes off track. Computation itself is the most important aspect of computing. Code and data are just complexity to manage. > Do I have a Customer? It goes into class Customer. Do I have a rendering context? It goes into class RenderingContext. I whole heartedly agree with this. The naive approach to domain modelling is to classify the primitives of a domain into classes and stop there. In actuality, the processor of those primitives is likely what your class should be, and those primitives ought to be methodless data structures. I.e., OrderFulfiller instead of Customer and Part classes.
- matwood 8y agoI disagree. SICP says "“In programming, we deal with two kinds of elements: procedures and data.” If we reduce that further it is really just data.
- corebit 8y agoThere is no one without the other. The data is unintelligible randomness without some algorithm to process it The code cant exist without some data schema to reference and has no value if there's no data instances to process.
- coldtea 8y ago>Computation itself is the most important aspect of computing. Code and data are just complexity to manage. Of course you're gonna write some computation, else there would be no program. That's not the point here. First, author doesn't mean "data" as in what comes in, it means the data structures of a program. Second, for the purposes of designing a program (and its computation part) data structures are a better guiding principle than objects. That's the argument being made.
- coolaliasbro 8y ago"I whole heartedly agree with this. The naive approach to domain modelling is to classify the primitives of a domain into classes and stop there. In actuality, the processor of those primitives is likely what your class should be, and those primitives ought to be methodless data structures." This is what I did not have the ability to articulate as well in an earlier comment. As far as I understand parent, the takeaway is that often OOP goes astray when the developer is unable to identify that a given need can be handled by generics/a parent class and instead instantiates their own class.
- alasdair_ 8y ago> OOP programs tend to only grow and never shrink because OOP encourages it. Most long-lived programs tend to grow, because people add new features to them. This isn't something unique to OOP. As for growth of OOP programs in particular - does no one ever refactor anything? Shrinking OOP code through refactoring is a daily occurrence at almost every job I've ever had.
- bunderbunder 8y agoI'm not sure that I agree 100% with all the points raised in this article, though that's possibly just a reaction to what reads to me as invective. Here's another bit of food for thought along those lines, though: If you take all the elements of what's typically considered to be good object-oriented design to their logical extremes, you end up with a bunch of objects that each have exactly one operation, and are configured at construction time. They may have some very simple internal state (think counters and caches), but you probably want to keep that to a minimum. The end result starts to look very, very similar to functional programming. An interface with one method is essentially a function. Constructor arguments do basically the same job as closures. Etc. When you're looking at things from that perspective, the big difference is that functional languages almost force you to work that way, whereas it takes consistent, conscious effort to do it in OOP.
- kumarvvr 8y agoI didn’t try to forget OOP per se, but I slowly adopted the authors guidelines regarding a data first approach. Now most of my objects are just wrappers around data, rather than analogies to real world objects. However I mostly am working on web apps so maybe this approach is more suitable to such apps. When working on desktop apps, during my initial days as a programmer, I found OOP based ui systems easy to grasp, but then this could be due to lack of experience.
- akerl_ 8y ago"One must never change the order here!" This is presented as a basic truth and then not really backed up, as far as I can tell. Why must I apply the order as the author believes?
- koonsolo 8y agoA language has 2 main purposes: 1. communication 2. representation of concepts 1 is pretty obvious, and for a programming language this means communication between a person to a computer 2 might not be as clear, but if you know that people cannot count in languages that have no numbers, it becomes obvious. There is a tribe that only has 0, 1 and many, and guess what, they can't tell the difference between 7 and 8. Now back to programming languages and their communication between computer and programmer: the old programming languages were very close to the computer. As languages evolved, they started to be become 'human', where it is easier for us to read and write them. OOP in that sense leans very close to concepts of normal humans. Objects, things objects can do, objects have separate responsibilities, etc. It's easy for a human to have such a model inside his head, because we already do this every day. Now as a programmer, most of the things that I need to do is make a representation of the real world into a program. Since the real world is made up of things that do stuff, it's easy to model it in such a concept. Most arguments against OOP always come from either a theoretical or academic background. But in the real world, with real companies, real problems to solve and real programmers, OOP is used. Because it lends itself really well for representing the real world in a computer model. EDIT: not saying that anyone that doesn't use OOP isn't a real programmer. But those people are more into the algorithmic or mathematical problem space, not a problem space where a real-world concept needs to be modeled. Most software is like the latter, and therefore most programs are OO. Is it the best solution for everything? Definitely not.
- hliyan 8y agoOOP in that sense leans very close to concepts of normal humans. Objects, things objects can do, objects have separate responsibilities, etc. This is not entirely accurate. Human languages are closer to functional languages: they have verbs that operate on nouns. Verbs are not attached to nouns, but rather, the operation of the verb is dependent on the noun.
- koonsolo 8y agoYet OOP reads more like English and functional programming more like math.
- jcolella 8y agoInteresting article. Though, the article should provide alternatives and speak to how use other types of programming paradigms might solve the issues that the person in the article is stating.
- makecheck 8y agoOO bugs that I see are actually in the “invisible” parts of objects, as these require more experience to know what is really going on. For example, failing to implement necessary operators (or worse, implementing them in ways that are subtly incorrect). Knowing how to implement object “glue” properly is something that just doesn’t come up if you’re using simpler programming styles, and in cases like these it’s better to pick the simplest and most maintainable approach that will suit the task to avoid pitfalls.
- 3pt14159 8y ago> At its core, every software is about manipulating data to achieve a certain goal > This part is very important, so I will repeat. goal -> data architecture -> code. Wait, what? No. That isn't what you just said. You said my goal was my goal and manipulating the data was the way to achieve that goal. Take Shopify. They had a goal: Make a ton of money by running ecommerce stores. They used OOP. They IPO'd and they're doing great. You can argue all you want about how they would have done better if they'd done some other programming style, but the reality is that almost every startup that I see win in fields like Shopify's (where there are a ton of different concerns with their own, disparate implementation specificities[0]) do so with OOP codebases.[1] In large corps like Google non-OOP with typed languages like Go might work great. Streams of data and all that. But for startups it's too slow. OOP is agile because you get some data and you can ask it "what can you do?" and you can trick functional or logical programming languages into kinda doing that too, but they do it poorly. [0] Even wording this in a non-OO way was a stupid waste of time. I could have just said "different models and methods" and 99% of the people here would have nodded and the 1% would have quibbled. [1] Some startups like WhatsApp are a bit of an exception, but even YouTube used Python.
- harimau777 8y agoWhen I'm coding, I often find myself in a situation where, in order to reach my goal, I need to use a "bad" language tool (e.g. eval), violate some principle of good coding (e.g. avoiding side effects), or just have to write ugly code. I've come to the conclusion that a lot of writing good code comes down to recognizing those situations and stepping back to find a way you can change your design or strategy to avoid needing the ugly code. I've never quite liked OOP, but I struggle to say exactly why. I wonder if some of it is that the class structure and hierarchies makes it difficult to step back and change the design in order to avoid having to write ugly code.
- anothergoogler 8y ago> Instead of a well-designed data store, OOP projects tend to look like a huge spaghetti graph of objects pointing at each other and methods taking long argument lists. Uh, what? FP projects are the ones with crazy argument lists, has OP even heard of the Law of Demeter? Does FP magically prohibit a huge spaghetti graph of functions and ad-hoc types pointing at each other? > The main point is: just because my software operates in a domain with concepts of eg. Customers and Orders, doesn't mean there is any Customer class, with methods associated with it. What an observation, it's all a bucket of bits so why name anything? Rub your hands together, mutter an incantation and voila, software without all that obnoxious structure!
- arunc 8y ago1. Stop teaching OOP with C++. 2. Document the anti patterns. OOP is not bad otherwise. I can't see how GUI frameworks can be easy and powerful without OOP.
- mromanuk 8y ago> the Customer concept is just a bunch of data in a tabular form in one or more DataStores, and “business logic” code manipulates the data directly. where lives this business logic? are different functions accessing the same data and modifying it? problems appears.
- jmartrican 8y agoI think for enterprise type software OOP works well. It easily allows us to re-use code and solve common problems once in a parent class and have that solution easily propagated to child classes. However, when developing a video game, I ran into quite a few OO design conundrums that IMO were the hardest programming problems to solve in my career. I started looking into data driven design, and while I never changed my code to implement it, it looked like it might have been easier for the video game. I do not know for sure. But I do know that getting OO right in the video game I was implementing was daunting. Maybe I was doing it wrong. The one issue we kept running into was how to design it so that the flow of dependencies flowed in one direction. That is to say, classes should not require references to classes that were higher up the food chain, and vice versa. It sucked when you realize that your Bullet class requires a reference to the BattleField class when the BattleField object was not being passed down through all the intermediate objects that separated the two. I would be willing to say that it could have been poor design, or rather not realizing that dependency earlier in the process to deal with it. But many things we did not know till the requirement or change came up. Then it was programming somersaults to deal with it. Eventually we did get better at re-arranging things as things came up, basically we got used to having to change a lot of the design at a drop of a dime. I do not know if data driven design would have helped, but it did sound like it was worth a shot. I must admit though, I do remember a data driven program i worked on, and it bothered me how much data had to be passed around that was not relevant to the method/class that was using it. And a lot of data got lumped together out of convenience.
- jtdev 8y ago“OOP apologists will respond that it's a matter of developer skill, to keep abstractions in check.” In my experience, the proliferation and use of ORMs makes keeping abstractions in check nearly impossible... in fact, I see ORM use as the primary design decision leading to the bastardization and convolution of sound OOP design.
- segmondy 8y agoThe conversion is about OOP, not ORM
- segmondy 8y agoI think most people forget that Edsger W. Dijkstra was a computer scientist not a software engineer. He most likely wrote programs, but not build software systems. As much as I've enjoyed most of his writings and musings, one must bear in mind that they most likely apply to programs not software systems built in the large. If you are writing one little program and have one type of data, it's easy to begin with data. When you have a complex system operating on 500 different types of data, it becomes easier to encapsulate with OOP.
- dmitripopov 8y agoEncapsulation never was my favorite aspect of OOP too, in fact I always try to create different classes for data and code - it brings in a lot of benefits. But OOP patterns described by GoF are brilliant things in terms of code reuse and maintenance costs.
- hota_mazi 8y ago> Object-oriented programming is an exceptionally bad idea which could only have originated in California. > — Edsger W. Dijkstra I don't understand why Dijkstra gets quoted so often when he has been demonstrably wrong on so many topics (see his opinion on BASIC too) and he was such a dogmatic and unreasonable person overall.
- hota_mazi 8y agoOOP is successful because it's very good at modeling the world that surrounds us. As much as people like to hate on inheritance and recommending composition instead (a reasonable advice), the bottom line is that you will encounter the pitfalls of inheritance only on very rare occasions. And inheritance enables so much flexibility and ease of maintenance that nothings comes close to it, not even FP. Specialization and polymorphism(s) are the reasons why OOP is around, successful, and will remain so for a while. Anyone pretending it's bad or broken is just click baiting and does not understanding the fundamental issues.
- VLM 8y agoSometimes the best way to decide what to do, is a OOP-like 100,000 line long legal code. Sometimes the best way to decide what to do, is something short and sweet yet possibly not entirely clear, like the Ten Commandments. When what the original designers chose was correct, everything will work quickly and reliably. When they don't, you'll suffer for a long time. Given that, you'll spend almost all of your wall clock time suffering and complaining about the designers selection being wrong. With a side effect of most of your suffering will be due to poorly implemented examples of the dominant paradigm. "AKA OOP SUX" In summary, given all of the above, there are two true statements that OOP works AND simultaneously you'll spend almost all of your mental effort on OOP not working. Generally, OOP being inappropriately hyper dominant at this time, means that non-OOP solutions will utterly master some very low hanging fruit for first movers who abandon OOP. I've seen some truly horrific object relational mappers trying to connect OOP to inherently functional software APIs, hardware device interfaces, "chronological engineering" in general, and persistent data stores. Not surprising if you're working in those areas, abandoning OOP will lead to massive success.
- oliwarner 8y agoIt's crazy how passionately people get behind their preferred paradigm. I think they all have a place, and can all be abused severely. I'm all for people —at least those who don't answer to me— picking one and running with it, but if you're going to try and tear another one down, at least make sure you understand what it does for the people that like it. TFA's author does not appear to.
- theFatemaLive 8y agoLearning and developing projects in Distributed Systems using Elixir made me realise the same..
- ttty 8y ago> The vast majority of essential code is not operating on just one object – it is actually implementing cross-cutting concerns. Example: when class Player hits() a class Monster, where exactly do we modify data? Monster's hp has to decrease by Player's attackPower, Player's xps increase by Monster's level if Monster got killed. Does it happen in Player.hits(Monster m) or Monster.isHitBy(Player p). What if there's a class Weapon involved? Do we pass it as an argument to isHitBy or does Player has a currentWeapon() getter? You have a function that has access to these objects. Based on that it will update the player and monster. Function onAttack(from as player, to as monster, weapon) player.addXp(weapon.xp) monster.addHealth(-weapon.damage) Probably you'll want to have immutable data instead of mutating this. (I'm on mobile so I can't put too much code) The reason you do this is to decouple code. You don't want the player to be aware of the monster, at least not in this scenario.
- dragonwriter 8y ago> For concurrency and multi-threading, I typically glue different logical components via message passing There's a word for the programming paradigm where you glue logical components together via message passing...
- jabajabadu 8y agoThis article seems to fit the template: Here are some abstract reasons why paradigm X is bad, and here is a class of problems that have a more straightforward solution in paradigm Y, therefore paradigm Y is better than X. The real message here is that if you have a problem that nicely maps onto a relational database then use the database-like approach instead of OOP. In my domain, I work on algorithms for a very specialized class of graphs whose structure and manipulation must obey a diverse set of constraints. I have tried implementing the core ideas using multiple popular paradigms but so far I did not find anything better than OOP.
- dejaime 8y agoI pretty much believe that all we have are bad solutions. OOP is a bad solution that is acceptable at a set of problems. Data oriented designs is an also bad solution that is acceptable at a set of problems. Anyone who has ever used any paradigm for big projects can do a write-up about how bad that paradigm is. The problem of OOP is not OOP, but actually knowing only OOP. That creates a lot of hammer and nail problems. The same would be true if data-oriented had the same popularity, and everything was data oriented. So, unless you ARE going to give me a __good__ solution, a silver bullet, it is silly to state that a whole paradigm is an absolute inferior. Especially when all you can give me is examples of bad paradigm-tech-problem matches or snippets of incompetent usage.
- coolaliasbro 8y agoThis is coming from a business consultant (BA/PM and configuration primarily), but in my experience, it seems like the OOP paradigm is fine in most cases and is leveraged in a functional/compositional fashion typically, so I fail to see the issue with OOP a paradigm. Generics and polymorphism can be used to basically create a functional system that only uses domain specific classes to handle edge cases. In short, OOP as currently used, in my experience working on numerous RIA/municipal/county government enterprise document management systems, seems perfectly adequate to the tasks at hand and can be used in an effectively functional way.
- smnplk 8y agoWhat is the point of OOP then, if you are using it in a functional way ? This just proves author's point. Do you truly use it in a functional way though, that would mean, that you care about separation of state and identity. If you are mostly using immutable collectons/objects with pure functions, then it's fine, but this is not OO.
- deleted 8y ago[deleted]
- smnplk 8y agoReading some of the comments here reminded me of a great talk by Stuart Halloway called Narcissistic Design.[1] [1] https://www.youtube.com/watch?v=LEZv-kQUSi4 https://www.youtube.com/watch?v=LEZv-kQUSi4
- luord 8y agoMost of the problems pointed out can be reduced into "confusing indirection as abstraction", which is a sin of many OOP developers, particularly those obsessed with design patterns. IMO, OOP is not inherently any more flawed than any other paradigm.
- ricardobeat 8y agoThis claim is not refuting any of the points presented.
- flavio81 8y agoWell, obviously the guy is not using Lisp(or Julia), because his problems are easily solved by multiple dispatch. Blame mediocre OOP languages (Java & friends), not OOP itself.
- rafaelvasco 8y agoDon't know why people keep insisting on this. OOP is a model. Functional is a model. Data oriented is a model. We as programmers just have to use them , in the most effective way possible to architect a solution to a problem. No one model of those can substitute any other. They complement themselves. There is bad OOP and effective OOP, just as there is bad Functional and effective Functional. The models are never bad by themselves. The programmers are. Any programmer that bashes OOP in favor of any other model is just making a fool of himself and exposing his ingenuity.
- in9 8y agoI really think these kind of articles are valuable in the sense that they make us question the way we code our applications. But I still think it's too easy to point to a problem without discussing possible solutions. I know the functional paradigm, focused on data streams and procedures, is where he is pointing at. But how does this facilitate the graph reference problem, for example? The thing with oop, besides that is easy, is that is diffuse. Any o'll tutorial will have an order+client example.
- ffanon 8y agoPreviously on HN: https://news.ycombinator.com/item?id=13850210 https://news.ycombinator.com/item?id=13850210 "Was object-oriented programming a failure?"