Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is meant by the term "true" object orientation

Tags:

c#

oop

ruby

I have been hearing a lot about Ruby and possibly even Javascript being "true" object oriented languages as opposed to C++ and C# which are class oriented (or template based) languages. What is meant by true OO and what are the advantages of this over the class/template approach?

like image 984
Jon Simpson Avatar asked Oct 30 '08 12:10

Jon Simpson


2 Answers

It's a subjective term used to promote languages. I've seen it used to say C# and Java are true object oriented languages in comparison to C++ because everything must be in a class (no global functions or variables) and all objects inherit from one Object class.

For Ruby, it may refers to how Ruby treats everything as an object, so you could write 1.to_s, instead of something like str(1) or String.valueOf(1). This is because Ruby makes no distinction between value and reference variables. In Javascript there are no classes and you just create extensible objects that could be cloned for reuse, this style of programming is known as Prototype-based programming.

C++ on the other hand is advertised as a multi-paradigm language that allows you to use several approaches such as object-oriented, generic and procedural programming. It doesn't stick to one paradigm.

But yeah, it's just a subjective term that could mean anything. Generally it refers to whether the language puts more emphasis on objects as opposed to other language elements like functions, templates, etc. Wikipedia's article on SmallTalk calls it a 'pure' object oriented language, and the description applies to Ruby as well:

Smalltalk is a 'pure' OO language, meaning that, unlike Java and C++, there is no difference between values which are objects and values which are primitive types. In Smalltalk, primitive values such as integers, booleans and characters are also objects, in the sense that they are instances of corresponding classes, and operations on them are invoked by sending messages. A programmer can change the classes that implement primitive values, so that new behavior can be defined for their instances--for example, to implement new control structures--or even so that their existing behavior will be changed. This fact is summarised in the commonly heard phrase "In Smalltalk everything is an object" (which would more accurately be expressed as "all values are objects", as variables aren't).

like image 83
Firas Assaad Avatar answered Oct 07 '22 05:10

Firas Assaad


The C++ issue is the following. C++ classes exist only in the source syntax. There's no run-time class object with attributes and methods.

In Python, everything's an object. An object's class is another object, with it's own methods and attributes. This is true of the smalltalk environment, also, which is a kind of benchmark of object-orientation.

I think the "true" object-orientation refers to those environments where everything's an object.

[Java falls short of this because it has primitive types.]

like image 32
S.Lott Avatar answered Oct 07 '22 05:10

S.Lott