TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

People Don't Understand OOP

25 点作者 coffeeaddict1超过 1 年前

10 条评论

dventimihasura超过 1 年前
Some people don&#x27;t understand OOP, sure. That&#x27;s the nature of things. However, many of us do understand. Consequently, nothing here comes as a surprise. And yet, we still think OOP has drawbacks where it&#x27;s often applied, even if it has benefits in other applications. If nothing else, one benefit is that it helps us organize code segments and reason about function dispatch. One drawback is that it&#x27;s not well-suited where it&#x27;s often applied. This is the well-known &quot;impedence mismatch.&quot; When that happens, it&#x27;s worth asking if there are other ways to organize code segments and reason about function dispatch, which are better-suited so they don&#x27;t experience these drawbacks. There are. Database constraints are one. Database triggers are another. They&#x27;re not the only ones and they&#x27;re not perfect, but then neither is OOP, and at least they have the virtue of being mated to the underlying data model perfectly.<p>Therefore, before we rush to say that other people don&#x27;t understand OOP, perhaps we should consider the possibility that WE don&#x27;t understand OOP if we insist on applying it where it doesn&#x27;t apply.
评论 #39211721 未加载
评论 #39211465 未加载
tialaramex超过 1 年前
Hmmm. I already don&#x27;t like it when we&#x27;re collecting together &quot;procedures and state&quot;.<p>One of the most poisonous things about the &quot;class&quot; whether that&#x27;s in Java or C++ is that it <i>looks</i> as though this procedure called &quot;chirp&quot; and this state called &quot;loudness&quot; are snuggled up together in my Bird class, after all in my source code they are literally on adjacent lines!<p>Of course they&#x27;re not, the actual mechanics are the same as in say Rust, where &quot;chirp&quot; lives in an impl block, while &quot;loudness&quot; is part of the actual data structure, or a language with full blown Uniform Method Call Syntax where the relevance of Bird to a &quot;chirp&quot; procedure is just spelled out wherever &quot;chirp&quot; is defined, not in the data structure of Bird itself.<p>I think the heart of OOP is the opacity, the fact that we (for some definition of we) aren&#x27;t allowed to poke around in the state directly, and this article talks about that idea at length, critiquing people who build a whole bunch of getter and setter mechanics for what is, in practice, just Plain Old Data and not really an object at all. So I think I&#x27;d start there, not by adding procedures.<p>So, I think a Doodad which may have internal state but we can&#x27;t touch it, is an Object, even if there seemingly aren&#x27;t any procedures for Doodads at all. But a Thingy, which has six named integers and a string inside it, that&#x27;s not an object in the OOP sense, that&#x27;s just some data, even if I have a whole <i>tonne</i> of procedures for Thingys.<p>This also makes sense when I don&#x27;t have total information. If you give me a Thingy, <i>I</i> can do things with that, regardless of whether you provide procedures, but if you give me a Doodad, I can&#x27;t do anything with that <i>unless</i> you provide procedures. Maybe <i>you</i> have procedures, but I can&#x27;t necessarily use them.
评论 #39211895 未加载
评论 #39212087 未加载
PaulHoule超过 1 年前
What all these discussions leave out is the importance of distributed object systems (COM, Binder, ...) and related technologies that played a prominent role in GUIs post 1990. Notably COM was designed so you could create &quot;objects&quot; in a non-OO language like C.<p>I see it as an important watershed because it seems to me the reliability and particularly performance reliability went downhill around the time this technology went mainstream. I remember plain old X Windows was rock solid but once KDE and Gnome came around that were based on this technology the Linux desktop became about as reliable as the Windows desktop.
评论 #39211378 未加载
评论 #39211370 未加载
评论 #39211165 未加载
mathgenius超过 1 年前
For me objects capture some notion of invariants in data that would otherwise just be a bunch of variables. This is usually indicated by functions that act on the data maintaining the invariants. Those functions are the methods.<p>I get that many people either don&#x27;t see, or don&#x27;t place much importance on the invariants of their data and so they are happy writing functions and even get annoyed by people and their over use of objects. Maybe these people are just way smarter than me; I definitely need objects&#x2F;classes to help me organize my code.
评论 #39211913 未加载
评论 #39219917 未加载
nightowl_games超过 1 年前
At its core, I view OOP as organizing code so the data and the methods that act on that data are linked. Usually there are some compile time restrictions on who can touch the data. You are able to be sure some state is valid because only this class can touch the state. If you think of OOP like that, it seems trivially good. Surely a lot better than a bunch of raw data hanging out that anyone can mutate at any time.<p>Inside of some class, you can then implement whatever you want inside of that class, ie:struct of arrays, or w&#x2F;e.<p>I don&#x27;t view &quot;inheritance&quot; as a necessity of OOP. Composition fits great. I don&#x27;t view &quot;array of structs&quot; as a necessity of OOP, nor over usage of heap allocations and pointer chasing. People associate OOP with this, but it&#x27;s not fundamental, it&#x27;s a poor, out dated mutation.<p>It seems like when people say &quot;OOP is bad&quot; they really mean &quot;over abstractions are bad&quot;, and yes, they are bad, but &quot;data oriented design&quot; and &quot;procedural code&quot; isn&#x27;t some silver bullet that&#x27;s gonna save you from writing trash code.<p>Ultimately, I consider ideal code to be &quot;verifiable on sight&quot;. Ie; I can read it easily and mentally verify that it is correct. Bad code is code that is very hard to verify correctness by reading. There&#x27;s an art to this and it doesnt always fit into these semantic buckets of &quot;OOP&quot; or &quot;Data Oriented Design&quot;.
评论 #39214625 未加载
roenxi超过 1 年前
Programming is mostly about understanding the problem domain. It is interesting that OOP had its heydey when everyone was building native GUI programs. The most likely situation was that programmers were developing abstractions that matched well to GUIs and those abstractions most closely mapped to OOP.<p>Things like functional programming, OOP, declarative programming, etc, might matter to language designers. They need these concepts to work out if their language is convenient&#x2F;internally consistent&#x2F;featureful and maybe these banner concepts help. Once the language has been built, I don&#x27;t think programmers actually care. The abstraction isn&#x27;t at the sweet spot where a developer gets the most power. The components of OOP (encapsulation, message passing, interfaces) are important and should be used liberally - but grouping them together under one heading is detrimental, because there will also be opportunities for other techniques from other schools of thought.<p>And as an aside inheritance seems to have been a mistake. I haven&#x27;t seen a lot of places where inheritance was the best idea. Interfaces yes, inheritance no.
评论 #39211650 未加载
评论 #39211639 未加载
评论 #39211585 未加载
mcbrit超过 1 年前
I&#x27;m sure I&#x27;m butchering this, but...<p>Alan Kay: an object should be just as powerful as the entire computer, ie an object is a recursive structure.<p>The rest is implementation details. The implementation details chosen over the past many years, particularly those favored by OOP, generally involve making objects way less powerful than the entire computer.
bcrosby95超过 1 年前
Correct me if I&#x27;m wrong, but can&#x27;t you encapsulate data with c? It&#x27;s been 25 years since I&#x27;ve used it but I thought it was possible.
DaiPlusPlus超过 1 年前
I&#x27;ll just leave this link right here: <a href="https:&#x2F;&#x2F;boxbase.org&#x2F;entries&#x2F;2020&#x2F;aug&#x2F;3&#x2F;case-against-oop" rel="nofollow">https:&#x2F;&#x2F;boxbase.org&#x2F;entries&#x2F;2020&#x2F;aug&#x2F;3&#x2F;case-against-oop</a> and wait for the <i>lively informed debate</i> to ensue...<p>(The article was a popular link when it was posted to HN back in 2020: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=30293622">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=30293622</a>)
eska超过 1 年前
It’s disingenuous to claim people don’t understand OOP (a term which can mean multiple things) by referring only to one of its possible meanings.<p>The performance comparison is also ridiculous.<p>The counter points are some random comments by the author’s friends rather than the plethora of excellent criticism out there.<p>This article is a lot of words without any substance.