设为首页 加入收藏

TOP

Python, C++ Comparision from AN OOP Programmer's Perspective
2019-04-15 14:52:09 】 浏览:20
Tags:Python Comparision from OOP Programmer' 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,
erif;">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 eva luating, 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 eva luating, the value stored in the memory space implicited associated by the identifier is obtained.





编程开发网
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Python:在Windows 10中搭建Pytho.. 下一篇.[Python 技术培训] 第一周幻灯片..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

array(4) { ["type"]=> int(8) ["message"]=> string(24) "Undefined variable: jobs" ["file"]=> string(32) "/mnt/wp/cppentry/do/bencandy.php" ["line"]=> int(217) }