Encapsulation unpythonic?

Chris Angelico rosuav at gmail.com
Sun Sep 1 04:21:41 EDT 2013


On Sun, Sep 1, 2013 at 6:10 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Java and C++ allow you to declare members as public, so it is *not true*
> that calling methods is the only way to change members. If you accept
> Steve Holden's (wrong) definition above, Java and C++ don't have
> encapsulation either.

That said, though, when you consider the language ecosystem rather
than just the language, there is a strong tendency for Java and C++
code to wrap everything up with functions (no public data members),
whereas Python code is far more likely to have external code directly
access data inside an object. You usually will find Java code calling
methods to change members, whereas that's done in Python only when
there's a need for it.

ChrisA



More information about the Python-list mailing list