TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The faster you unlearn OOP, the better for you and your software

209 pointsby jxubover 6 years ago

52 comments

mabboover 6 years ago
I&#x27;m always confused when people criticize OOP, because most of the time the criticisms they use are just plain bad programming. Or they&#x27;re using hyperbole that isn&#x27;t really useful.<p>You want to know why OOP is useful and common? Because it&#x27;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.<p>But like most easy things, OOP still works well enough even when it&#x27;s done badly. That&#x27;s not a bad thing. Working software beats non-working software.<p>We shouldn&#x27;t be telling people &quot;stop using OOP! It&#x27;s only for idiots!&quot;. 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.
评论 #18527220 未加载
评论 #18527530 未加载
评论 #18527013 未加载
评论 #18527057 未加载
评论 #18527007 未加载
评论 #18527274 未加载
评论 #18531550 未加载
评论 #18527008 未加载
评论 #18527149 未加载
评论 #18527045 未加载
eitlandover 6 years ago
I read this quickly to see if this was the piece that should convince me.<p>It was not. It is, IMO, a collection of strawmen.<p>People have abused OOP? Yes.<p>But<p>- citing FizzBuzz Enterprise Edition (which is really funny even for us Java&#x2F;.Net developers because it is so horribly wrong)<p>or writing this<p>- <i>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.</i><p>again IMO, demonstrate that the author never really understood OOP.<p>What probably is true however is that a lot of people should unlearn the OOP they learned in school.
评论 #18527071 未加载
评论 #18526968 未加载
评论 #18526886 未加载
评论 #18527184 未加载
评论 #18526702 未加载
评论 #18526836 未加载
评论 #18526861 未加载
jryan49over 6 years ago
&gt; 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&#x27;s hp has to decrease by Player&#x27;s attackPower, Player&#x27;s xps increase by Monster&#x27;s level if Monster got killed. Does it happen in Player.hits(Monster m) or Monster.isHitBy(Player p). What if there&#x27;s a class Weapon involved? Do we pass it as an argument to isHitBy or does Player has a currentWeapon() getter?<p>Not saying this is the right way to do things but, if you&#x27;re actually going to go 100% OO on something:<p>Player.hits(Monster) returns Hit<p>Hit takes a Player and a Monster in constructor, and has with(Weapon)<p>You end up with:<p>Player.hits(Monster).with(Weapon)<p>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.<p>It does read kind of nicely IMO...
评论 #18526864 未加载
评论 #18527127 未加载
评论 #18527109 未加载
评论 #18526856 未加载
评论 #18527268 未加载
评论 #18526971 未加载
评论 #18527454 未加载
评论 #18529926 未加载
评论 #18527329 未加载
评论 #18526850 未加载
评论 #18528293 未加载
hliyanover 6 years ago
This has been shared on HN many years ago, but I&#x27;m linking again in case there are younger engineers who might be unaware of this classic rant: <i>Execution in the Kingdom of Nouns</i> : <a href="https:&#x2F;&#x2F;steve-yegge.blogspot.com&#x2F;2006&#x2F;03&#x2F;execution-in-kingdom-of-nouns.html" rel="nofollow">https:&#x2F;&#x2F;steve-yegge.blogspot.com&#x2F;2006&#x2F;03&#x2F;execution-in-kingdo...</a>
评论 #18527257 未加载
评论 #18526805 未加载
cedover 6 years ago
I&#x27;ve never liked classical OOP much, but multiple dispatch is a lovely paradigm. One doesn&#x27;t define _classes_ per se, but rather just plain old boring structs.<p><pre><code> struct Player xp::Int end struct Monster hp::Int end function hit(p::Player, m::Monster) p.xp += 10 m.hp -= 20 end </code></pre> The nicest thing is how one one doesn&#x27;t need inheritance to &quot;add a method&quot; to an object. One just defines my_function(s::String) to be whatever, and it doesn&#x27;t interfere with anyone else&#x27;s code.
评论 #18527131 未加载
评论 #18526918 未加载
评论 #18527167 未加载
评论 #18527040 未加载
评论 #18526949 未加载
crazygringoover 6 years ago
A lot of these initial points I don&#x27;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...<p>BUT, &quot;cross-cutting concerns&quot; is where I think the main valid argument is. In my experience, OOP is just way too <i>restrictive</i> of a model, by forcing you to shoehorn data and code into an object hierarchy that doesn&#x27;t reflect the meaning of what&#x27;s going on.<p>So I totally agree with the conclusion: just store your data in &quot;dumb&quot; 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&#x2F;n&#x27;t support).
评论 #18526896 未加载
corebitover 6 years ago
&gt; Data is more important than code<p>Nope. Right there at the beginning is where the author goes off track.<p>Computation itself is the most important aspect of computing. Code and data are just complexity to manage.<p>&gt; Do I have a Customer? It goes into class Customer. Do I have a rendering context? It goes into class RenderingContext.<p>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.<p>I.e., OrderFulfiller instead of Customer and Part classes.
评论 #18527068 未加载
评论 #18528259 未加载
评论 #18527059 未加载
agumonkeyover 6 years ago
The 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.<p>There&#x27;s good bits in OO. You can find articles about how parameterizing large `switch` statements into objects can lead to obvious improvements.<p>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&#x2F;theorem to grok.
jmartricanover 6 years ago
I 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.<p>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.<p>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&#x2F;class that was using it. And a lot of data got lumped together out of convenience.
jabajabaduover 6 years ago
This 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.<p>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.<p>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.
partycoderover 6 years ago
Bashing imperative + structured + OOP is valid if you have a viable alternative. That viable alternative is proper namespacing, modularity and functional programming.<p>If your alternative is another form of spaghetti your problem is not OOP. Your problem is the way you build abstractions.<p>If your procedures and functions, the foundation of your program, are poorly thought, then you laid a shitty foundation for everything that follows.
koonsoloover 6 years ago
A language has 2 main purposes:<p>1. communication<p>2. representation of concepts<p>1 is pretty obvious, and for a programming language this means communication between a person to a computer<p>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&#x27;t tell the difference between 7 and 8.<p>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 &#x27;human&#x27;, where it is easier for us to read and write them.<p>OOP in that sense leans very close to concepts of normal humans. Objects, things objects can do, objects have separate responsibilities, etc. It&#x27;s easy for a human to have such a model inside his head, because we already do this every day.<p>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&#x27;s easy to model it in such a concept.<p>Most arguments against OOP always come from either a theoretical or academic background.<p>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.<p>EDIT: not saying that anyone that doesn&#x27;t use OOP isn&#x27;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.
评论 #18527129 未加载
alasdair_over 6 years ago
&gt; OOP programs tend to only grow and never shrink because OOP encourages it.<p>Most long-lived programs tend to grow, because people add new features to them. This isn&#x27;t something unique to OOP.<p>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&#x27;ve ever had.
adnzzzzZover 6 years ago
&gt;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&#x27;s hp has to decrease by Player&#x27;s attackPower, Player&#x27;s xps increase by Monster&#x27;s level if Monster got killed. Does it happen in Player.hits(Monster m) or Monster.isHitBy(Player p). What if there&#x27;s a class Weapon involved? Do we pass it as an argument to isHitBy or does Player has a currentWeapon() getter?<p>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?
评论 #18526981 未加载
评论 #18526722 未加载
评论 #18526656 未加载
评论 #18526760 未加载
评论 #18526658 未加载
lispmover 6 years ago
Some things never die. comp.object on usenet (15+ years ago) had a regular &#x27;guest&#x27; explaining why table-oriented programming is better than OOP:<p><a href="http:&#x2F;&#x2F;www.oocities.org&#x2F;tablizer&#x2F;top.htm" rel="nofollow">http:&#x2F;&#x2F;www.oocities.org&#x2F;tablizer&#x2F;top.htm</a>
评论 #18527243 未加载
评论 #18526950 未加载
Const-meover 6 years ago
OOP is not a silver bullet but for some classes of problems it&#x27;s the best tool available.<p>That&#x27;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.
评论 #18532743 未加载
rafaelvascoover 6 years ago
Don&#x27;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.
DanielBMarkhamover 6 years ago
There&#x27;s something very important here. It also tends to be overstated. As a former OOP guy, I struggle with explaining what&#x27;s going on with people that don&#x27;t see it yet.<p>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.<p>It&#x27;s not all bad. But there are problems with where we are. Big problems. We need to understand them.
3pt14159over 6 years ago
&gt; At its core, every software is about manipulating data to achieve a certain goal<p>&gt; This part is very important, so I will repeat. goal -&gt; data architecture -&gt; code.<p>Wait, what? No. That isn&#x27;t what you just said. You said my goal was my goal and manipulating the data was the way to achieve that goal.<p>Take Shopify. They had a goal: Make a ton of money by running ecommerce stores.<p>They used OOP. They IPO&#x27;d and they&#x27;re doing great.<p>You can argue all you want about how they would have done better if they&#x27;d done some other programming style, but the reality is that almost every startup that I see win in fields like Shopify&#x27;s (where there are a ton of different concerns with their own, disparate implementation specificities[0]) do so with OOP codebases.[1]<p>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&#x27;s too slow. OOP is agile because you get some data and you can ask it &quot;what can you do?&quot; and you can trick functional or logical programming languages into kinda doing that too, but they do it poorly.<p>[0] Even wording this in a non-OO way was a stupid waste of time. I could have just said &quot;different models and methods&quot; and 99% of the people here would have nodded and the 1% would have quibbled.<p>[1] Some startups like WhatsApp are a bit of an exception, but even YouTube used Python.
VLMover 6 years ago
Sometimes 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&#x27;t, you&#x27;ll suffer for a long time. Given that, you&#x27;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. &quot;AKA OOP SUX&quot;<p>In summary, given all of the above, there are two true statements that OOP works AND simultaneously you&#x27;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.<p>I&#x27;ve seen some truly horrific object relational mappers trying to connect OOP to inherently functional software APIs, hardware device interfaces, &quot;chronological engineering&quot; in general, and persistent data stores. Not surprising if you&#x27;re working in those areas, abandoning OOP will lead to massive success.
bunderbunderover 6 years ago
I&#x27;m not sure that I agree 100% with all the points raised in this article, though that&#x27;s possibly just a reaction to what reads to me as invective.<p>Here&#x27;s another bit of food for thought along those lines, though: If you take all the elements of what&#x27;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.<p>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.<p>When you&#x27;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.
hota_maziover 6 years ago
&gt; Object-oriented programming is an exceptionally bad idea which could only have originated in California. &gt; — Edsger W. Dijkstra<p>I don&#x27;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.
dejaimeover 6 years ago
I 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.<p>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.<p>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.
anothergooglerover 6 years ago
&gt; 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.<p>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?<p>&gt; The main point is: just because my software operates in a domain with concepts of eg. Customers and Orders, doesn&#x27;t mean there is any Customer class, with methods associated with it.<p>What an observation, it&#x27;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!
harimau777over 6 years ago
When I&#x27;m coding, I often find myself in a situation where, in order to reach my goal, I need to use a &quot;bad&quot; language tool (e.g. eval), violate some principle of good coding (e.g. avoiding side effects), or just have to write ugly code. I&#x27;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.<p>I&#x27;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.
coolaliasbroover 6 years ago
This is coming from a business consultant (BA&#x2F;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&#x2F;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.<p>In short, OOP as currently used, in my experience working on numerous RIA&#x2F;municipal&#x2F;county government enterprise document management systems, seems perfectly adequate to the tasks at hand and can be used in an effectively functional way.
评论 #18528277 未加载
segmondyover 6 years ago
I 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&#x27;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&#x27;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.
makecheckover 6 years ago
OO 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.
dnauticsover 6 years ago
Should be pointed out that this refers to C++&#x2F;Java&#x2F;Ruby&#x2F;python style objects, and not smalltalk&#x2F;erlang style objects, which is a message passing model for data storage.
评论 #18526940 未加载
评论 #18526919 未加载
评论 #18526840 未加载
in9over 6 years ago
I really think these kind of articles are valuable in the sense that they make us question the way we code our applications.<p>But I still think it&#x27;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?<p>The thing with oop, besides that is easy, is that is diffuse. Any o&#x27;ll tutorial will have an order+client example.
akerl_over 6 years ago
&quot;One must never change the order here!&quot;<p>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?
vnoriloover 6 years ago
I find that I generally agree. However, I have the intuition that good data-oriented design requires an exceptionally solid understanding of the problem domain.<p>You might say that any good design requires that. I&#x27;m not going to disagree. But if there&#x27;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.<p>Of course, preliminary abstraction has a nasty habit of becoming permanent.
kumarvvrover 6 years ago
I 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.<p>However I mostly am working on web apps so maybe this approach is more suitable to such apps.<p>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.
oliwarnerover 6 years ago
It&#x27;s crazy how passionately people get behind their preferred paradigm. I think they all have a place, and can all be abused severely.<p>I&#x27;m all for people —at least those who don&#x27;t answer to me— picking one and running with it, but if you&#x27;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&#x27;s author does not appear to.
dmitripopovover 6 years ago
Encapsulation 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.
theFatemaLiveover 6 years ago
Learning and developing projects in Distributed Systems using Elixir made me realise the same..
mromanukover 6 years ago
&gt; 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.<p>where lives this business logic? are different functions accessing the same data and modifying it? problems appears.
luordover 6 years ago
Most of the problems pointed out can be reduced into &quot;confusing indirection as abstraction&quot;, which <i>is</i> a sin of many OOP developers, particularly those obsessed with design patterns.<p>IMO, OOP is not inherently any more flawed than any other paradigm.
评论 #18529928 未加载
smnplkover 6 years ago
Reading some of the comments here reminded me of a great talk by Stuart Halloway called Narcissistic Design.[1]<p>[1] <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=LEZv-kQUSi4" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=LEZv-kQUSi4</a>
ffanonover 6 years ago
Previously on HN: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=13850210" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=13850210</a> &quot;Was object-oriented programming a failure?&quot;
dragonwriterover 6 years ago
&gt; For concurrency and multi-threading, I typically glue different logical components via message passing<p>There&#x27;s a word for the programming paradigm where you glue logical components together via message passing...
jcolellaover 6 years ago
Interesting 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.
flavio81over 6 years ago
Well, obviously the guy is not using Lisp(or Julia), because his problems are easily solved by multiple dispatch.<p>Blame mediocre OOP languages (Java &amp; friends), not OOP itself.
hota_maziover 6 years ago
OOP is successful because it&#x27;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.<p>And inheritance enables so much flexibility and ease of maintenance that nothings comes close to it, not even FP.<p>Specialization and polymorphism(s) are the reasons why OOP is around, successful, and will remain so for a while. Anyone pretending it&#x27;s bad or broken is just click baiting and does not understanding the fundamental issues.
jryan49over 6 years ago
&gt; Encouraging complexity<p>Picking a satire piece on how something can be abused is not a great argument of &quot;this thing is bad&quot;.<p>For example, I&#x27;d argue anything written in an OOP language is going to be more readable than this (from the obfuscated C contest) <a href="https:&#x2F;&#x2F;www.ioccc.org&#x2F;2018&#x2F;algmyr&#x2F;prog.c" rel="nofollow">https:&#x2F;&#x2F;www.ioccc.org&#x2F;2018&#x2F;algmyr&#x2F;prog.c</a><p>Also, complex systems tend to benefit from OOP because complex systems can have multiple combinations of behaviors. Something IMO OOP is useful for.
aruncover 6 years ago
1. Stop teaching OOP with C++. 2. Document the anti patterns.<p>OOP is not bad otherwise. I can&#x27;t see how GUI frameworks can be easy and powerful without OOP.
thanatropismover 6 years ago
I&#x27;m a simple man. I don&#x27;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&#x2F;Tardos).<p>Like everyone who&#x27;s doing stuff with data, I live in Python now. I&#x27;m fairly conversant in functional idioms (wrote a monad tutorial when it was all the fashion), but like objects because they&#x27;re a straightforward way to keep data and code together in a bundle that can be passed around and serialized.<p>The typical situation for me is machine learning - I could have &quot;fit_to_data&quot; functions that return matrices or otherwise sum&#x2F;product types (as they called it in Haskell) containing the estimated parameters and &quot;predict_from_param_struct&quot; 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<p><pre><code> data LogisticParams a = LogisticP (Matrix a) </code></pre> (I don&#x27;t remember Haskell syntax anymore) but I&#x27;m not sure how I&#x27;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&#x2F;hyperparameter search tooling. The idiom above would require me to study the hierarchy of types upwards and whatever advanced features of the language they&#x27;re using; but even if the scikit-learn team is using features of Python outside my understanding (say, async, or low-level numpy&#x2F;communication with C libraries) I&#x27;m still able to adhere to a convention.<p>---<p>That said, have y&#x27;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(&quot;kitchen&quot;)? 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&#x27;s trying to decide how TopologicalSpace.MeasurableSpace fits with IntegrableFunctions.ProbabilityMeasures...<p>[1] <a href="https:&#x2F;&#x2F;www.researchgate.net&#x2F;publication&#x2F;275540145_Formal_Concept_Analysis_-_Overview_and_Applications" rel="nofollow">https:&#x2F;&#x2F;www.researchgate.net&#x2F;publication&#x2F;275540145_Formal_Co...</a>
LaserToyover 6 years ago
Give a man enough rope and he’ll hang himself.
tttyover 6 years ago
&gt; 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&#x27;s hp has to decrease by Player&#x27;s attackPower, Player&#x27;s xps increase by Monster&#x27;s level if Monster got killed. Does it happen in Player.hits(Monster m) or Monster.isHitBy(Player p). What if there&#x27;s a class Weapon involved? Do we pass it as an argument to isHitBy or does Player has a currentWeapon() getter?<p>You have a function that has access to these objects. Based on that it will update the player and monster.<p><pre><code> Function onAttack(from as player, to as monster, weapon) player.addXp(weapon.xp) monster.addHealth(-weapon.damage) </code></pre> Probably you&#x27;ll want to have immutable data instead of mutating this.<p>(I&#x27;m on mobile so I can&#x27;t put too much code)<p>The reason you do this is to decouple code. You don&#x27;t want the player to be aware of the monster, at least not in this scenario.
Michaelanjelloover 6 years ago
I 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.<p>Unfortunately, when asked to design an OOP architecture in a job interview, if you don&#x27;t adhere to its religious enterprisy notions, you can risk failing the interview.
jtdevover 6 years ago
“OOP apologists will respond that it&#x27;s a matter of developer skill, to keep abstractions in check.”<p>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.
评论 #18527279 未加载
sunsebover 6 years ago
Yeah 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.