On Jan 7, 1:07 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
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(self):
       return self._someAttr
  def getSomeOtherAttr(self):
        return self._someOtherAttr

[x.getSomeAttr() for x in listOfMyWhatevers if x.getSomeOtherAttr() ==
'whatever']

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

[x._someAttr for x in listOfMyWhatevers if x._someOtherAttr ==
'whatever']



-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to