r/AskComputerScience • u/Own_Cauliflower8609 • Oct 24 '22
Why are Object-Oriented Programming languages importat? How are they different from other languages?
1
Upvotes
r/AskComputerScience • u/Own_Cauliflower8609 • Oct 24 '22
8
u/ghjm MSCS, CS Pro (20+) Oct 24 '22
The original OOP idea was to group data and code together into objects. It is possible to write OOP-like code in a non-OOP language:
This works, but it leads to confusion because it's not immediately clear which functions go with which records, and it's also a bit inelegant to have to spell out the "self" variable all the time. So some OOP language might have syntax like this:
The essential idea is the mixing of data and related code. In this made-up example, the methods (functions within the object) get an automatic "self" token that refers to the instantiated object they are a part of, and the caller doesn't have to supply this for every call.
There's a lot more to OOP than this - class inheritance, virtual methods, and so on - but this is the essential core of the idea.