Is POO the same in all languages?

Asked

Viewed 971 times

24

Is the way of structuring, programming in POO the same in all languages? For example, class, interface, etc...

  • 1

    No, it resembles but is not equal.

3 answers

28


Object-oriented language

In accordance with already answered to AP in previous question, object orientation is not exactly a language mechanism. The paradigm can be applied to any language, even those which people do not consider to be object-oriented.

I think it’s bad enough the whole object-oriented language thing. Even worse is to say that it is fully object-oriented, which does not exist in practice, nor is Smalltalk (which alias is absurdly different from everything we use, and according to its creator, the object-oriented term was coined by him, and therefore only this language or those that look like it are actually OO, but the concept mainstream is the OO adopted by C++).

He had already shown that OOP is a secondary paradigm and cannot exist by itself.

Some languages use specific mechanisms to help meet the precepts of the paradigm. The most common is to have class mechanism, interfaces, etc. Others have prototype mechanism. Some languages in the background are travesty prototypes of classes, very common in dynamic languages such as PHP. Nothing prevents there from being another, entirely different mechanism.

In fact there are controversies about what is OOP. Even some people talk about OOP when they’re actually talking about OOD (design object-oriented) that are similar things but are not the same thing, but that is another matter. Some people do not even agree on the mechanisms necessary for language to be considered at least partially as object-oriented.

Mechanisms

Each specific mechanism can be implemented in different ways. There are various types of polymorphism, and the language can implement all or none. Yes, yet you can do polymorphism without the language being easy, as long as she is Turing Complete and every programming language must be. Generic polymorphism even makes language a participant of another paradigm. The same goes for other mechanisms. As far as I know the only unique mechanism of OOP, to date today, is the inheritance.

You have language you don’t have interface, or has a different way, has language that has trait, has language that implements this and other mechanisms in the wrong way, has language that claims to have a mechanism, but actually does not. Has language that even has a specific syntax that helps to do OOP, as already said before.

Mechanisms exist to provide more convenience, performance and other secondary gains.

J didn’t know what class is, today you know. It uses both mechanisms, although one is more concrete and the other is just syntax sugar. Some will say that everything is syntax sugar, which I disagree with. Everything is abstraction, which is a different concept.

All language features will interact with specific OOP features and will make changes to their implementation. For example, it is different to do OOP in language dynamic or static typing, structural or nominal typing, and so on.

Syntax

In the comments we talk about syntax. I have my doubts whether this is relevant, but certainly the syntax is different, it would be almost impossible for it to be the same. Even in sister languages the syntax may be similar, but it is different. If it is the same, it is the same language. I think I actually wanted to know about semantics, and it’s usually different too, might even everything I wrote above.

Completion

Reinforce what Renan said, we can no longer think that the Earth is flat or vaccine causes autism. We are in the information age, where everything is very easy to learn, but it is also very easy to unlearn. We have never had so many cases of information being consumed quickly and superficially giving room to learn everything wrong and be in the hands of those who more easily manipulate the perceived reality.

I say and I repeat that most people think they’re object-oriented programming when they’re not. People think that creating a class is OOP, and it’s not. In fact most OO code would be better written differently, even by the programmer’s inability to understand what OO is.

Programming X Design

I have a theory that OO was created to separate the function of the engineer from the encoder. Most developers are just coders. I think it makes sense in this case. The engineer is a very skilled subject to make a good design of the application and delegates to the encoder the creation of the algorithms and implementation details.

Of course the professional can, and often does both, and can have OO advantage even in these cases, what is tragic is when only barely know how to code and try to be an engineer.

Read more:

  • 1

    Por isso discordo levemente do Renan quando diz que JS não sabe o que é classe. Ela usa os dois mecanismos, ainda que um seja mais concreto e outro é apenas syntax sugar. I was inflamed when I wrote that, it was bad XD

  • @Renan even imagined, after I edit my own :) I understand this a lot, live happening to me :)

13

tl;dr mathematically yes; in practice, one or the other paradigm makes some constructions meaningless

Object orientation is a mathematical branch of treating mathematical entities that have attributes and behaviors. This concept, after being very well established in mathematics, was absorbed in programming languages. In this sense, object orientation is the same in all languages.

On the other hand, there are alternatives to how this is done. There are non-ctiped languages, languages with dynamic typing, and languages with duck typing. Duck-typing languages, for example, may dispense with the use of interfaces. Also take into account that static typing helps the programmer realize that there is an error in his code at the time of compilation (static code analysis).

There are also implementation differences that are very relevant. In C++, to use polymorphism, it is necessary to declare that the method is virtual, in Java every private method is considered virtual.

I talk more about interfaces and objects in that other answer, with a special focus on Java at the end of the response. Focusing here on the first item in the list of the above linked response:

interfaces are promises of behavior

In duck-typing languages, if I have an object with method access pop, peek and push then I have a behavior of deque; I don’t need to say this to this object, it just has this behavior, I don’t need to say that it promises it a priori.

In some languages I can dynamically assign methods to existing objects, thus making an object to fulfill a behavior promise in run time. This dynamic method insertion is usually associated with duck typing.

13

Not.

A lot of people learn in college or Internet tutorials that C# and Java are object-oriented because they have class concepts. And that’s just it. And it’s because of this general acceptance of vomited information that we have people who also believe that the Earth is flat and that vaccines cause autism.

Javascript does not know what a class is, but is object-oriented Javascript allows OO programming without necessarily making use of class abstraction. There are still other languages that do not have the concept of prototyping and inheritance without Javascript typing, but are also object oriented.

So no, object orientation is not the same in all languages. Instead of asking that, the nicer it would be to ask yourself which after all is object orientation and why she came up.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.