Why less emphasis on private data?

BJörn Lindqvist bjourne at gmail.com
Sun Jan 7 01:54:00 CET 2007


On 6 Jan 2007 16:07:05 -0800, time.swift at gmail.com <time.swift at gmail.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?

Google for "python for consenting adults"

Or ask yourself the opposite question. Why does C++ and C# prefer more
private data? It is given that emphasizing private data
(encapsulation) leads to more internal complexity and more lines of
code because you have to write getters and setters and stuff. With
that in mind, why do you think that data encapsulation makes code less
error prone? Can you prove it? Or do you have anecdotal evidence of
where data encapsulation saved your ass?

IMHO, that data hiding is good, is one of those ideas that have been
repeated so much that virtually everyone thinks it is true.  But
Python proves that it isn't necessarily so.

-- 
mvh Björn



More information about the Python-list mailing list