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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

How Class-based Programming Sucks (2011)

140 点作者 vimes656超过 11 年前

14 条评论

barrkel超过 11 年前
Class-based programming works great for GUI toolkits. In most other contexts, the suitability is variable. OO is a horrible match for compilers, for example.<p>The article is chasing down the wrong tree when he tries to build an Option type in C++, though. The normal OO way to handle the same class of functionality as ADT sum types is to use separate subclasses. What he&#x27;s not acknowledging is that OO and functional+ADTs both only handle half the expression problem[1], in different ways. There&#x27;s no absolute superiority for either model. It depends on the domain.<p>Less mutability is good almost everywhere though. The lack of persistent data types is a blight on almost all non-functional container libraries.<p><a href="http://en.wikipedia.org/wiki/Expression_problem" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Expression_problem</a>
评论 #6900773 未加载
评论 #6900339 未加载
评论 #6900373 未加载
评论 #6900394 未加载
评论 #6901449 未加载
评论 #6900351 未加载
choult超过 11 年前
The thing about &quot;Class based Programming&quot; - or Object Orientated Programming - is that it allows you to model a problem domain in real-world terms. No one approach is ever going to be perfect; OO being mutable makes it perhaps less founded (on the face of things) on formal principles, but for a lot of large codebases it can have a great beneficial effect on readability and maintainability - cognitive overhead is, perhaps, reduced when you can &quot;ground&quot; your understanding in real-life terms.<p>At the end of the day, pick what language and coding paradigms best suit your problem domain and you as a coder. Pick right, and there&#x27;s no mistake there.
评论 #6900288 未加载
评论 #6900159 未加载
评论 #6900292 未加载
评论 #6900452 未加载
评论 #6900178 未加载
评论 #6900328 未加载
评论 #6900285 未加载
评论 #6900299 未加载
评论 #6900448 未加载
评论 #6900266 未加载
评论 #6900214 未加载
评论 #6903237 未加载
评论 #6900364 未加载
xcthulhu超过 11 年前
Okay, for one:<p>1. Dynamically Typed Languages (LISP, Erlang, Smalltalk, Python, Ruby, and Javascript) are all easier than Haskell, JAVA, C++ or any other typed language for working with ADTs. Whether the language is OO or not isn&#x27;t really relevant. On the other hand, you loose type-safety&#x2F;efficient representations. But life is filled with choices, different tools are good for different things at different times.<p>2. You can have closures in a class based language. Here&#x27;s some rather exotic Python code that uses both for measuring the performance of iterators: <a href="https://github.com/wearpants/measure_it/blob/master/measure_it/__init__.py" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;wearpants&#x2F;measure_it&#x2F;blob&#x2F;master&#x2F;measure_...</a><p>Smalltalk and Scala also have closures. It&#x27;s not an either&#x2F;or for classes vs. closures in programming language land.<p>3. There&#x27;s more to concurrency than shared memory, so immutability is again a weapon that is good for some battles. If you have an app which you&#x27;ve factored into workers, unless they are on the same machine they&#x27;ll need to communicate. Having your data be serializable is more important than having things be immutable in this context. What a worker does with data while it is handling it can involve lots of mutation.<p>So everyone should take a big breath, and remember that there&#x27;s no one way to think about software and there&#x27;s no universal rules, other than probably P != NP and stuff like that.
评论 #6900843 未加载
评论 #6907456 未加载
rowanseymour超过 11 年前
Best (and most humorous) argument against Java&#x27;s object oriented obession that I&#x27;ve ever read is: <a href="http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html" rel="nofollow">http:&#x2F;&#x2F;steve-yegge.blogspot.com&#x2F;2006&#x2F;03&#x2F;execution-in-kingdom...</a>
评论 #6900381 未加载
评论 #6900451 未加载
评论 #6906265 未加载
arithma超过 11 年前
I find a mix between Object-Orientation to model the problem, and a lot of functional thinking in the &#x27;solving&#x27; department to be the most comfortable. The modernisation (as in taking features from the old languages into the newer ones) of C++, C#, Java, Obj-C etc. are all liberal with this direction.
评论 #6900283 未加载
rayiner超过 11 年前
This is a very good article. The point about mutable state is key. Class based programming encourages you to treat objects as little bags of mutable state, instead of as values, and everything goes downhill from there. Its one thing to not go all the way to disallowing mutation. Its another to encourage it to be used pervasively.
评论 #6905672 未加载
pbsd超过 11 年前
&gt; You may even have to inherit a base class or implement an interface. Subtype polymorphism is a very poor substitute for closures. This is why C++ algorithm library is unusable.<p>Does anybody understand what the author means by this? STL&#x27;s algorithm library does not use class hierarchies for anything. And they often take functions (be they free functions, lambdas, or functors) as arguments.
评论 #6900424 未加载
评论 #6904561 未加载
评论 #6900443 未加载
auggierose超过 11 年前
In case you don&#x27;t know ML, you should. Also note that though OCaml is the most popular ML dialect right now, Standard ML is where it all started (PolyML is a good Standard ML implementation: <a href="http://www.polyml.org/" rel="nofollow">http:&#x2F;&#x2F;www.polyml.org&#x2F;</a>)
评论 #6900233 未加载
评论 #6900307 未加载
draegtun超过 11 年前
Also see: <i>The problem with OOL is not the OO</i> by Carl Sassenrath (from 2009) - <a href="http://www.rebol.com/article/0425.html" rel="nofollow">http:&#x2F;&#x2F;www.rebol.com&#x2F;article&#x2F;0425.html</a><p>PS. Just submitted to HN - <a href="https://news.ycombinator.com/item?id=6900426" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=6900426</a>
swah超过 11 年前
Relevant recent tweet by the creator of the Io Language, Steve Dekorte: <a href="https://twitter.com/stevedekorte/status/411045428361056256" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;stevedekorte&#x2F;status&#x2F;411045428361056256</a><p>I suppose most folks here disagree?
评论 #6901693 未加载
alkonaut超过 11 年前
I agree, mostly, with the conclusions. &quot;Classes&quot; as a method of code re-use is dead. However, his conclusion that ML would dominate C# and Java as a language, I highly contest.<p>The most important thing in my opinion is tools and platform support. Show me a fast, good looking IDE with good autocomplete&#x2F;intellisense&#x2F;integrated debugger and UI tools for ML. See?<p>Is there an abundance of libraries and api wrappers available (that doesn&#x27;t require you to do straight C-interop)? See?<p>Also: the design of a language should be done with the tools in mind. While there is not much difference between norm(vec) and vec.norm() the latter is the form that supports autocomplete. So even for functional languages, being able to use member properties and member functions is an absolute reqirement to support the tooling that we expect.<p>You <i>could</i> say that F# dominates C#. It has almost the same tool and library support, while having the features you expect from an ML type language.
评论 #6914319 未加载
评论 #6903563 未加载
al2o3cr超过 11 年前
&quot;The obvious conclusion is that ML simply dominates Java (and C#) as a language. Time to switch.&quot;<p>The obvious conclusion is that any statement that contains the phrase &quot;the obvious conclusion is&quot; is 100% BS, including this one.
toolslive超过 11 年前
mutable state is not a problem per se. _Shared_ mutable state however, is a recipe for disaster.<p>There are other problems with Object-Orientation. For example, it tends to scatter allocation which has performance impact. ( see this nice presentation: <a href="http://harmful.cat-v.org/software/OO_programming/_pdf/Pitfalls_of_Object_Oriented_Programming_GCAP_09.pdf" rel="nofollow">http:&#x2F;&#x2F;harmful.cat-v.org&#x2F;software&#x2F;OO_programming&#x2F;_pdf&#x2F;Pitfal...</a> )<p>If performance is not an issue, I&#x27;d guess the price you pay for OO is that you eschew parallelism and concurrency.
评论 #6900446 未加载
评论 #6900197 未加载
mtdewcmu超过 11 年前
A language can&#x27;t suck just because it isn&#x27;t Haskell or ML.
评论 #6905525 未加载