Why less emphasis on private data?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gabriel Genellina

    #61
    Re: Why less emphasis on private data?

    At Wednesday 10/1/2007 04:33, Hendrik van Rooyen wrote:
    >Oh I am of the opposite conviction - Like the fellow of the Circuit Cellar
    >I forget his name ( Steve Circia (?) ) who said: "My favourite Programming
    >Language is Solder"..
    Almost right: Steve Ciarcia.


    --
    Gabriel Genellina
    Softlab SRL






    _______________ _______________ _______________ _____
    Preguntá. Respondé. Descubrí.
    Todo lo que querías saber, y lo que ni imaginabas,
    está en Yahoo! Respuestas (Beta).
    ¡Probalo ya!


    Comment

    • Steve Holden

      #62
      Re: Why less emphasis on private data?

      Paul Boddie wrote:
      Paul Rubin wrote:
      >Right, the problem is if those methods start changing the "private"
      >variable. I should have been more explicit about that.
      >>
      >class A:
      > def __init__(self):
      > self.__x = 3
      > def foo(self):
      > return self.__x
      >>
      >class B(A): pass
      >>
      >class A(B):
      > def bar(self):
      > self.__x = 5 # clobbers private variable of earlier class named A
      >
      Has this ever been reported as a bug in Python? I could imagine more
      sophisticated "name mangling": something to do with the identity of the
      class might be sufficient, although that would make the tolerated
      "subversive " access to private attributes rather difficult.
      >
      Paul
      >
      It would also force the mangling to take place at run-time, which would
      probably affect efficiently pretty adversely (thinks: should really
      check that mangling is a static mechanism before posting this).

      regards
      Steve
      --
      Steve Holden +44 150 684 7255 +1 800 494 3119
      Holden Web LLC/Ltd http://www.holdenweb.com
      Skype: holdenweb http://del.icio.us/steve.holden
      Blog of Note: http://holdenweb.blogspot.com
      See you at PyCon? http://us.pycon.org/TX2007

      Comment

      • Bart Ogryczak

        #63
        Re: Why less emphasis on private data?

        On Jan 7, 1:07 am, "time.sw...@gma il.com" <time.sw...@gma il.com>
        wrote:
        Coming from a C++ / C# background, the lack of emphasis on private data
        seems weird to me. I've often found wrapping private data useful to
        prevent bugs and enforce error checking..
        >
        It appears to me (perhaps wrongly) that Python prefers to leave class
        data public. What is the logic behind that choice?
        Often it´s a question of efficiency. Function calls in Python are
        bloody slow. There is no "inline" directive, since it´s intepreted,
        not compiled. Eg. consider code like that:

        class MyWhatever:
        ...
        def getSomeAttr(sel f):
        return self._someAttr
        def getSomeOtherAtt r(self):
        return self._someOther Attr

        [x.getSomeAttr() for x in listOfMyWhateve rs if x.getSomeOtherA ttr() ==
        'whatever']

        You´d get it running hundreds times faster doing it the "wrong" way:

        [x._someAttr for x in listOfMyWhateve rs if x._someOtherAtt r ==
        'whatever']



        Comment

        • Paul Rubin

          #64
          Re: Why less emphasis on private data?

          Steve Holden <steve@holdenwe b.comwrites:
          class A(B):
          def bar(self):
          self.__x = 5 # clobbers private variable of earlier class named A
          Has this ever been reported as a bug in Python? I could imagine more
          sophisticated "name mangling": something to do with the identity of the
          class might be sufficient, although that would make the tolerated
          "subversive " access to private attributes rather difficult.
          It would also force the mangling to take place at run-time, which
          would probably affect efficiently pretty adversely (thinks: should
          really check that mangling is a static mechanism before posting this).
          I think it could still be done statically. For example, the mangling
          could include a random number created at compile time when the class
          definition is compiled, that would also get stored in the class object.

          I guess there are other ways to create classes than class statements
          and those would have to be addressed too.

          Comment

          Working...