Why less emphasis on private data?

Jussi Salmela tiedon_jano at hotmail.com
Mon Jan 8 12:37:25 EST 2007


Neil Cerutti kirjoitti:
> On 2007-01-08, hg <hg at nospam.org> wrote:
>> sturlamolden wrote:
>>
>>> The designers of Java, C++, C#, Ada95, Delphi, etc. seem to think that
>>> if an object's 'internal' variables or states cannot be kept private,
>>> programmers get an irresistible temptation to mess with them in
>>> malicious ways. But if you are that stupid, should you be programming
>>> in any language? The most widely used language is still C, and there is
>>> no concept of private data in C either, nor is it needed.
>>
>> void test(void)
>> {
>>   static int i;
>> }
>>
>>
>> Do you agree that i is "private" to test ?
> 
> In C one uses the pointer to opaque struct idiom to hide data.
> For example, the standard FILE pointer.
> 

To surlamolden: I don't know how you define private, but if one defines 
in C an external static variable i.e. a variable outside any functions, 
on the file level, the scope of the variable is that file only.

To hg: One does not need in C the static keyword to make a variable 
defined inside a function i.e. a so called 'automatic variable' private 
to that test. Automatic variables are private to their function by 
definition. The static keyword makes the variable permanent i.e. it 
keeps its value between calls but it is of course private also.

To Neil Cerutti: If a programmer in C has got a pointer to some piece of 
memory, that piece is at the mercy of the programmer. There's no data 
hiding at all in this case.

To whom it may concern: please stop comparing C and Python with regard 
to privacy and safety. They are two different worlds altogether. Believe 
me: I've been in this world for 2.5 years now after spending 19 years in 
the C world.

Cheers,
Jussi



More information about the Python-list mailing list