Python dynamic attribute creation
WANG Cong
xiyou.wangcong at gmail.com
Fri Jun 25 23:39:57 EDT 2010
On 06/26/10 00:11, Neil Hodgson <nyamatongwe+thunder at gmail.com> wrote:
> WANG Cong:
>
>> 4) Also, this will _somewhat_ violate the OOP princples, in OOP,
>> this is and should be implemented by inherence.
>
> Most object oriented programming languages starting with Smalltalk
> have allowed adding attributes (addInstVarName) to classes at runtime.
Thanks, I have to admit that I know nothing about Smalltalk.
>From what you are saying, Smalltalk picks a way similar to setattr() in
Python? Because you mentioned 'addInstVarName' which seems to be a
method or a builtin function. If so, that is my point, as I mentioned
earlier, switching to setattr() by default, instead of using assignments
by default. :)
> Low level OOPLs like C++ and Delphi did not implement this for
> efficiency reasons.
>
Hmm, although this is off-topic, I am interested in this too. C++ does
have metaprogramming, but that is actually static metaprogramming (using
templates), not dynamic metaprogramming here. I am wondering if
efficiency is the only reason why C++ doesn't have dynamic
metaprogramming, since C++ is a static programming language I think if
this limits C++ to implement its dynamic metaprogramming actually...
Thanks.
--
Live like a child, think like the god.
More information about the Python-list
mailing list