dynamic-on-demand classes Re: Copy constructors

Roman Suzi rnd at onego.ru
Sun Aug 12 16:55:43 EDT 2001


On Sun, 12 Aug 2001, Guido van Rossum wrote:

>That may be usually for *your* classes :-).  Most of *my* classes
>don't need this.  If the default is static, most users will not have
>to change it (if my expectation is right that most classes don't need
>to be dynamic), and so most classes will benefit from the speed-up of
>static classes.  Since classes that need to be dynamic are naturally
>discovered during coding or testing (they give errors when trying to
>change a class), selectively turning on the dynamics is easy -- and it
>requires an explicit decision on the programmer's behalf.

Well, it seems appropriate to repeat my thought about
dynamic-on-demand here.

The thought is simple: let all classes be static UNTIL operation is
requested which need them to be dynamic. Then, __dynamic__ attribute
appears = 1 and everybody is happy: those, who want to sacrifice speed for
flexibility just let that operations happen. Those who use static classes
just have them.

Adding EXPLICIT __dynamic__ makes things hairy and no better
than adding "static" before "class".

class SleepyStatic:
  def __init__(self, x):
    if x:
      SleepyStatic.newattr = x       # now __dynamic__ == 1
    else:
      self.newattr = x               # __dynamic__ remains not defined or 0


- this allows Python to be flexible (when needed) and
more speedy (when this is wanted more).


Sincerely yours, Roman Suzi
-- 
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Sunday, August 12, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "Is it possible to feel gruntled?" _/





More information about the Python-list mailing list