Why does python not have a mechanism for data hiding?

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Wed Jun 11 10:31:58 CEST 2008


Russ P. a écrit :
> On Jun 10, 1:04 am, Bruno Desthuilliers <bruno.
> 42.desthuilli... at websiteburo.invalid> wrote:
> 
>> If you hope to get a general agreement here in favor of a useless
>> keyword that don't bring anything to the language, then yes, I'm afraid
>> you're wasting your time.
> 
> Actually, what I hope to do is to "take something away" from the
> language, and that is the need to clutter my identifiers with leading
> underscores.
> 
> I find that I spend the vast majority of my programming time working
> on the "private" aspects of my code, and I just don't want to look at
> leading underscores everywhere. So I usually just leave them off and
> resort to a separate user guide to specify the public interface.
> 
> I'll bet many Python programmers do the same. How many Python
> programmers do you think use leading underscores on every private data
> member or method, or even most of them for that matter?

First point : please s/private/implementation/g. As long as you don't 
get why it's primary to make this conceptual shift, the whole discussion 
is hopeless.

Second point : I've read millions of lines of (production) python code 
these last years, and I can assure you that everyone used this 
convention. And respected it.


> I'll bet not
> many. (See the original post on this thread.) That means that this
> particular aspect of Python is basically encouraging sloppy
> programming practices.

Bullshit. Working experience is here to prove that it JustWork(tm).

> What I don't understand is your visceral hostility to the idea of a
> "priv" or "private" keyword.

Because it's at best totally useless.

> If it offends you, you wouldn't need to
> use it in your own code. You would be perfectly free to continue using
> the leading-underscore convention (unless your employer tells you
> otherwise, of course).

My employer doesn't tell me how to write code. I'm not a java-drone. My 
employer employ me because he is confident in my abilities, not because 
he needs some monkey to type the code.

The point is not *my* code, but the whole free python codebase. I 
definitively do not want it to start looking anything like Java. Thanks.

> I get the impression that Python suits your own purposes and you
> really don't care much about what purpose others might have for it.

Strange enough, every time I read something like this, it happens that 
it comes from someone who is going to ask for some fundamental change in 
a language used by millions of persons for the 15+ past years just 
because they think it would be better for their own current project.

> I
> am using it to develop a research prototype of a major safety-critical
> system. I chose Python because it enhances my productivity and has a
> clean syntax, but my prototype will eventually have to be re-written
> in another language. I took a risk in choosing Python, and I would
> feel better about it if Python would move up to the next level with
> more advanced features such as (optional) static typing and private
> declarations.

I'm sorry, but I don't see any of this as being "a move up to the next 
level".

> But every time I propose something like that,

fundamental change in the language for your own (perceived, and mostly 
imaginary) needs, that is...

> I get all
> kinds of flak from people here who do their hacking and care little
> about anyone else's needs.

No one needs another Java. Now what happens here is that *you* come here 
explaining everyone that they need to adapt to the way *you* think 
things should be.

> With a few relatively small improvements, Python could expand its
> domain considerably and make major inroads into territory that is now
> dominated by C++, Java, and other statically compiled languages. But
> that won't happen if reactionary hackers stand in the way.

So anyone not agreeing with you - whatever his experience, reasons etc - 
is by definition a "reactionnary hacker" ? Nice to know.

> Side note: I've been looking at Scala, and I like what I see.  It may
> actually be more appropriate for my needs, but I have so much invested
> in Python at this point that the switch will not be easy.

So instead of taking time to learn the tool that would fit your needs, 
you ask for fundamental changes in a language that fits millions other 
persons needs ? Now let's talk about not caring about other's needs...



More information about the Python-list mailing list