From: Peng Yu on
Hi

I'm still kind of confused about the terminology on classes in python.

Could you please let me know what the equivalent terms for the
following C++ terms?

constructor
destructor
member function
member variable
virtual member function
function

I think that C++ "function" is equivalent to python "function" and C++
"member function" is equivalent to python "method". But I couldn't
locate where the original definitions of the corresponding python
terms in the manual as these term appear many times. Could you please
point me where to look for the definition of these python
corresponding terms?

--
Regards,
Peng
From: Thomas Jollans on
On 07/26/2010 11:52 PM, Peng Yu wrote:
> Hi
>
> I'm still kind of confused about the terminology on classes in python.
>
> Could you please let me know what the equivalent terms for the
> following C++ terms?
>
> constructor

constructor.

This consists of the class constructor method, __new__, and of the
instance initialization method, __init__
In practice, __init__ is really "the constructor".
http://docs.python.org/py3k/reference/datamodel.html#object.__new__

> destructor

destructor.

http://docs.python.org/py3k/reference/datamodel.html#object.__del__

> member function

method.
Look for "instance method" below
<URL:http://docs.python.org/py3k/reference/datamodel.html#the-standard-type-hierarchy>

> member variable

attribute, instance attribute, instance variable.

> virtual member function

all methods are virtual.

> function

function.


> I think that C++ "function" is equivalent to python "function" and C++
> "member function" is equivalent to python "method". But I couldn't
> locate where the original definitions of the corresponding python
> terms in the manual as these term appear many times. Could you please
> point me where to look for the definition of these python
> corresponding terms?

http://docs.python.org/py3k/reference/datamodel.html should answer all
your questions.
From: Rhodri James on
On Mon, 26 Jul 2010 22:52:06 +0100, Peng Yu <pengyu.ut(a)gmail.com> wrote:

> Hi
>
> I'm still kind of confused about the terminology on classes in python.
>
> Could you please let me know what the equivalent terms for the
> following C++ terms?

Seriously, we can't keep doing your thinking for you. The answers
to all your questions are section 9 of the tutorial.

--
Rhodri James *-* Wildebeeste Herder to the Masses
From: Tim Chase on
On 07/26/10 18:15, Thomas Jollans wrote:
>> destructor
>
> http://docs.python.org/py3k/reference/datamodel.html#object.__del__

One small caveat -- IIRC, in Java/C++ the destructor is
guaranteed to be called with a certain amount of context. I find
Python's __del__ almost useless since things it may rely upon can
arbitrarily be destroyed before the __del__ is called.

-tkc




From: Steven D'Aprano on
On Mon, 26 Jul 2010 16:52:06 -0500, Peng Yu wrote:

> Could you please let me know what the equivalent terms for the following
> C++ terms?
>
> constructor
> destructor
> member function
> member variable
> virtual member function
> function


(1) Python new-style classes have a constructor __new__ and an
initialiser __init__. Some people describe both as constructors, but
that's strictly incorrect because the instance has already been
constructed by the time __init__ is called. (Old-style classes don't have
__new__, only __init__.)

(2) Python destructors are called __del__ , but you shouldn't use them
unless you really know what you are doing.

(3) "Member functions" are methods.

(4) "Member variables" are attributes. If you have to distinguish between
attributes which live on the instance from one that lives on the class,
"instance attribute" and "class attribute".

(5) I believe that all methods in Python are virtual.

(6) Function.


> I think that C++ "function" is equivalent to python "function" and C++
> "member function" is equivalent to python "method". But I couldn't
> locate where the original definitions of the corresponding python terms
> in the manual as these term appear many times. Could you please point me
> where to look for the definition of these python corresponding terms?

I believe you are right, but I can't find a definition of C++ "member
function" that makes sense. Can you please point me where to look for the
definition of these C++ terms?

I don't believe the Python Language Reference explicitly defines terms
such as "attribute" and "method", but the tutorial may help:

http://docs.python.org/tutorial/classes.html

Quote:
In C++ terminology, all class members (including the data members)
are public, and all member functions are virtual.


Note: although the docs occasionally use the term "members" for
attributes, it is considered more standard to use "attribute" or "method"
unless discussing data types defined at the C layer.


--
Steven