设为首页 加入收藏

TOP

Python, C++ Comparision from AN OOP Programmer's Perspective
2019-04-25 14:47:45 】 浏览:26
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,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书=>待买 下一篇.[Python 技术培训] 第一周幻灯片..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目