DEV Community

Discussion on: Is Object-Oriented Programming "Dangerous"?

Collapse
 
yawaramin profile image
Yawar Amin

Hola, you have also misunderstood the core principle of OOP. It's not about hierarchy. It's about objects with internal state which send messages to each other. Here's Alan Kay's original thoughts on OOP, summarized: wiki.c2.com/?AlanKaysDefinitionOfO...

Notice, no mention of hierarchies. Just objects, sending messages, belonging to classes.

Collapse
 
yucer profile image
yucer • Edited

Hello, the hierarchies are built when you try to describe the complexity of the problem.

You can not describe 5000 objects that represents sale orders and 2000 objects that represent purchase orders. You describe a set of objects with a common representation, that is the class. And there is stuff in common between them, so you create order with the commonalities and express the minimal differences in sale order and purchase order. That is the inheritance. When you put all of that together there is a hierarchy.

There is not a single hierarchy, a subset of them are linked by the composition, when an object is built with objects of other hierarchies (by example: a sale order contain order items, each one composed of a product, a quantity and a price.). But the product might belong to its own hierarchy of that describe the different classes of products.

Also many entities that generate financial operations, use to be linked to the accounts. And the accounts are classified in a hierarchy (the chart of accounts)

According to the functional requirements, the OOP might represent many of these hierarchies by mean of objects or not. Nevertheless, the hierarchy must persist somehow in the data structures... because they represent entities of the problem domain.

So not only OOP have mechanism to describe hierarchies, or hierarchies are used to organize the code reusing previous definitions. Those hierarchies do actually exist in the complexity of the real world.

The original article say:

OOP is not natural for the human brain, our thought process is centered around “doing” things — go for a walk, talk to a friend, eat pizza. Our brains have evolved to do things, not to organize the world into complex hierarchies of abstract objects.

And that is an incorrect assertion. The human brain did evolve to work with abstractions and generalizations, and the natural language was formed with those structures on them. This process requires classification of the information. So yes, humans constantly organize their mental representation of the world in hierarchies.

When you ask a child to describe an object, he doesn't answer with the set of rules that can be applied to it. He answer with the nearest abstract concept and the different characteristics that it has.

Adult: What is this ?
Child: It is a chair.
Adult: And what is a chair ?
Child: An object with four legs and a back that persons use to sit.

The child doesn't remember the details of 20 chairs of its classroom, if they seem similar for its practical purpose. The brain is somehow optimized to remember only useful information.

Basically, in the real world the behaviour is deeply bound to state.

OOP focus on structure and state and FP focus on behaviour.

Humans use hierarchies in their abstraction mechanisms for remember and reasoning. They identify new concepts identifying the difference in structure (state) and behaviour.

I am open to think that it might be better for the performance of our machines, for the scalability of our systems, a representation that focuses on behaviour. But then a bigger gap might arise in the process of communication (programming), that might be the reason why more expertise seem to be needed for FP.

There is no need to distort the notion of the reality. They are just different paradigms for describing it.