What python idioms for private, protected and public?

Sion Arrowsmith siona at chiark.greenend.org.uk
Fri Sep 30 17:33:47 CEST 2005


Michael Schneider  <michaelschneider at fuse.net> wrote:
>I have been coding in C++ since the late 80's and Java since the late 90's.
>
>I do use private in these languages, with accessors to get at internal 
>data.
>
>This has become an ingrained idiom for me.

The question is, has it become a purely instinctive idiom, or are
you getting real benefit from it?

My experience over a similar length of time (well, maybe not quite
so long with C++) is that private is far more likely to hinder than
help, and that protected is a more sensible state for things which
aren't on the public interface. And since working seriously with
Python, I've come round to the point of view that the public
interface should be defined by what you document it as, and not
enforced by language gimmicks. Which is just duck typing from
another angle.

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |    -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump



More information about the Python-list mailing list