Encapsulation in Python

Rick Johnson rantingrickjohnson at gmail.com
Tue Mar 15 02:09:45 EDT 2016


On Monday, March 14, 2016 at 1:12:14 PM UTC-5, sohca... at gmail.com wrote:

[...a whole lot of my quotes, snipped for bandwidth...]

@GROUP: I don't know what the heck happened in this thread,
but everyone involved was having a nice respectful
conversation about encapsulation, interfaces, and modules,
and then BartC and Mark showed up, and the thread went off
on a wild tangent. Whilst the participation of members and
the CoC are important topics, i hope we put aside these
petty issues, and get back to productive discussions soon.
Thanks.

> I don't think you'll find anyone that disagrees with you
> here.
> 
> If you're seeing a method "width", then whoever wrote that
> method is a terrible programmer.  Method names should
> *always* contain some sort of verb.  As you just said,
> self-documenting names are the key to short learning
> curves.
> 
> IMO, if you intend an attribute to be read-only, then you
> should use a getter, even in Python, 

Even though many of our fellow members would argue that this
is overkill, your advice is good advice, and i strongly
support this position.

> and of course prefix the actual value with an underscore
> to show it should not be accessed publicly.

Agreed!

> The only time you should see "someObject.width" is if
> width is both readable and writable.  Of course, Using
> @property to add some logic to the setting/getting is
> fine.

Yes. More wonderful, and consistent, advice here. You sir,
have restored my faith in humanity.




More information about the Python-list mailing list