Live data from Hacker News

Classes Considered Harmful [pdf]

web.cecs.pdx.edu

31–40 of 129 posts

Re: Classes Considered Harmful [pdf]

#31

There seems to be a common fixation on objects "modeling the real world" with the counter argument for classes being that they don't model the real world. True, there isn't a physical chair class in real life(philosophically, there aren't even chairs), but there is a common abstract idea of what would describe the function and attributes of a chair. Granted, it differs a little from person to person, but objects them…

Right, classes are a way to explain to the computer 'there's gonna be a bunch of objects that are all "chairs". You'll be able to treat all of them in a similar kind of way.' But you should consider that starting with classes might not be the only way to do that.

Inform7, in its beautifully literal (not to say literate) way, captures this very simply with the way it defines classes (what it calls 'kinds'):

     A chair is a kind of thing. A chair can be comfy or hard.
     Your favorite armchair is a comfy chair in the living room.
But to be fair, Inform7 is object-oriented because it's a language for describing worlds (interactive fictional worlds, specifically) that are made of objects, and the utility of the metaphor for building, say, a website, may not be as strong.

Other languages might use other techniques to capture 'chairness' without having to start off by describing the class of 'chair'. Maybe you define the protocols chairs support (sittability?), or you just rely on dynamic typing and write code that just assumes whatever is passed to it is a chair and can be sat upon, without the code ever needing to be able to divine an object's chairness. That's useful! you can sit on things that aren't chairs, after all. If you can only build objects from classes, though, you can get yourself into the situation where you find yourself having to find a way to compose a 'chair' instance into your 'bed' class so you can allow someone to sit on the bed without having to copy paste code.

Re: Classes Considered Harmful [pdf]

#32
post #8

Most eye-opening moment in my software engineering class was when the professor asked, of four core OO features (don't recall the precise list now), which was superfluous. The answer, of course, was inheritance, and once the question was asked it wasn't hard to see how much better life could be without it. I've been on an anti-inheritance kick ever since. Now I see how much better life can be without OO entirely, but…

What do you use to implement interfaces then? Generic interfaces are the one single feature that made OO popular for GUI programming; what by its turn is the one application that made OO popular. And it's still the most powerful of the OO concepts (what is shame really).

Are you referring to the fact that in Java interfaces are basically pure virtual classes? That always felt like an implementation detail to me. For example, both Go and Rust have interfaces without inheritance.

Re: Classes Considered Harmful [pdf]

#33

I like this kind of critical papers but I cannot agree with the author in this case. I have studied this problem quite deeply while working on concept-oriented programming and concept-oriented data model ( http://conceptoriented.org/ ) for many years by also trying to minimize the number of basic constructs. Yet, my conclusion is that classes are actually needed. There are several major reasons for that. One of them…

http://conceptoriented.org/savinov/publicat/arxiv_1501_00720... Just skimmed the 'Cross-Cutting Concerns' in your paper above. Isn't AOP far more general than what you propose there? Please correct any misunderstanding but per the parent based approach you describe -- "cross-cutting concerns are modularized in parent incoming methods and this functionality is injected in child methods" -- you would need to duplicate…

> Isn't AOP far more general than what you propose there?

Yes, definitely AOP provides much more freedom in injecting behavior to other parts of the code - it is its main goal while COP has different goals.

> you would need to duplicate a CCC e.g. logging in each distinct 'parent'

No, because in COP, "Parents are Shared Parts of Objects" [1], that is, a parent may have many children. Inheritance in COP is inclusion. If a parent implements a method then it will be reused by all its children.

[1] http://bibliography.selflanguage.org/_static/parents-shared-...

Re: Classes Considered Harmful [pdf]

#34
post #14
post #8

Most eye-opening moment in my software engineering class was when the professor asked, of four core OO features (don't recall the precise list now), which was superfluous. The answer, of course, was inheritance, and once the question was asked it wasn't hard to see how much better life could be without it. I've been on an anti-inheritance kick ever since. Now I see how much better life can be without OO entirely, but…

I think that inheritance can have a place. It makes a lot of sense when writing //small variations// on an otherwise rich inner class. Small variations might include layering on a different input or output mechanism, or possibly handling 'extra' data that the object stores but previously did not modify.

You can achieve the same with composition or parametrisation. Both of which are the only tools in a functional language.

Re: Classes Considered Harmful [pdf]

#35
> "classes do not “model the real world”"

Classes are supposed to model sets (of objects), that is, instances represent real objects and classes represent real sets of objects. So the question is whether sets are as real as the members they consist of. For example, if a set of chairs is a reality that we can comprehend and want to represent in the system.

Yet, I think the problem is that we are probably not happy how classes model sets in OOP. They actually do not - and it is a major problem. (Classes in OOP are mostly templates for instantiating objects.) Also, we are not happy with how inheritance works and it also limits possible benefits of classes. But it is not a reason to say that classes per se are harmful. I would say that they are not as good as they could be :(

Re: Classes Considered Harmful [pdf]

#36
post #9

There seems to be a common fixation on objects "modeling the real world" with the counter argument for classes being that they don't model the real world. True, there isn't a physical chair class in real life(philosophically, there aren't even chairs), but there is a common abstract idea of what would describe the function and attributes of a chair. Granted, it differs a little from person to person, but objects them…

> As far as I can tell, in most OO languages, there's no reason why classes must use inheritance, though I am certainly willing to be schooled in that regard. That there is no precise definition of what a class is and isn't, and that the traditional notion of a class conflates several independent concepts, is precisely the big criticism! To my mind "traditional classes" means inheritance, and recent languages without…

Forgive my ignorance. What do Rust and Go call their data structures that are analogous to classes?

Re: Classes Considered Harmful [pdf]

#37
Computer science gets a lot of papers with arguments for a certain way of doing things.

Very few with controlled experiments to find out if a way of doing things is better than another.

Every time I mention this, people say that it is hard to do such experiments. Yes, it is hard to actually know things. while it is very easy to make plausible arguments, for almost anything.

Re: Classes Considered Harmful [pdf]

#38
post #9

Earlier quoted context omitted.

> As far as I can tell, in most OO languages, there's no reason why classes must use inheritance, though I am certainly willing to be schooled in that regard. That there is no precise definition of what a class is and isn't, and that the traditional notion of a class conflates several independent concepts, is precisely the big criticism! To my mind "traditional classes" means inheritance, and recent languages without…

Forgive my ignorance. What do Rust and Go call their data structures that are analogous to classes?

Well, in Go they are just Types

Re: Classes Considered Harmful [pdf]

#39

Computer science gets a lot of papers with arguments for a certain way of doing things. Very few with controlled experiments to find out if a way of doing things is better than another. Every time I mention this, people say that it is hard to do such experiments. Yes, it is hard to actually know things. while it is very easy to make plausible arguments, for almost anything.

Just challenge the promoter to rewrite a c++ base program in their new favorite method, paradigm.

For example, the author of this paper can try to rewrite the google chrome browser - a huge C++ project in the "non-Harmful" way.

Re: Classes Considered Harmful [pdf]

#40
post #14

Earlier quoted context omitted.

I think that inheritance can have a place. It makes a lot of sense when writing //small variations// on an otherwise rich inner class. Small variations might include layering on a different input or output mechanism, or possibly handling 'extra' data that the object stores but previously did not modify.

You can achieve the same with composition or parametrisation. Both of which are the only tools in a functional language.

You can achieve the same in any Turing complete language.

However, composition and parametrization require up-front design and are usually only viable for large-ish variations.

As the parent said, inheritance handles the case of refinement, that is, programming by difference, which composition and parametrization handle with difficulty (if planned for) or not at all (if not planned for).

The bad rap inheritance gets is that it is often misused in places where composition or parametrization were appropriate. But that's just the old "it hurts when I poke myself in the eye with a sharp stick": don't do that.

http://www.metaobject.com/papers/Diplomarbeit.pdf

Post reply on HN