Python, C++ Comparision from AN OOP Programmers Perspective

"Data model" is a terminology appeared in the official python language reference. In the model inplemented by python, objects are python’s abstration for data.

It is worth mention that python has a different language architecture as oposed to C++. In python, everything can be regarded as an object. Here I quote from https://docs.python.org/3/reference/datamodel.html: "In a sense, and in conformance to Von Neumann’s model of a ‘stored program computer,’ code is also represented by objects.). Under this framework, object is everywhere in python, it is the basic component of a python program, which I believe, make python an object driven programming language.

In C++, not everything can be seen as an object. Actually, the entities (component)of a C++ program are values, objects,references, functions, enumerators, types, class members, templates, template specializations, namespaces, parameter packs, and |this| pointer. Objects, in terms of one class, is only a component in C++ and is designed to be existed parallelly with values, functions, types, etc. In another word, a C++ object is associated with a type, a value, etc. They all have the same weight under C++ architecture. Type, value, and other "properties" (as you may refer it), is not regarded to exist as data blocks attached to objects. Object is not the first class citizen in C++.

In python, variable is a mechanism that acts as a n-to-1 mapping which links a specific literal (name/alphabet sequence, called identifier) in the program to a memory space.

After the execuation of the following code:

###code start

a=1

#the memory address of 1 is 0x0000

b=a

###code end

literal "a" and "b" would both represent a memory address: 0x0000. When evaluating, the value stored in the memory space represented by the identifier is obtained.

In contrast, variable in C++ is a mechanism that acts as a 1-to-1 mapping which links a identifier in the program to a specific value. The identifier has an implicit associated memory space which is fixed (thus C++ is called to be a static language).

After the execuation of the following code:

###code start

a=1

#the memory address of a is 0x0000, in which 1 is stored

b=a

#the memory address of b is 0x0001, in which 1 is stored

###code end

literal "a" and "b" would both represent a memory address: 0x0000. When evaluating, the value stored in the memory space implicited associated by the identifier is obtained.

,闲淡时光里徜徉书海。本文是旅游开心句子说说心情,希望对大家有帮助!

Python, C++ Comparision from AN OOP Programmers Perspective

相关文章:

你感兴趣的文章:

标签云: