Re: Why less emphasis on private data?



Neil Cerutti kirjoitti:
On 2007-01-08, hg <hg@xxxxxxxxxx> 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
.



Relevant Pages

  • Re: Getting and Setting and best practise
    ... to interpret which private variable you wanted. ... C - you make seperate getter/setter functions for each private ... if I've been a good little programmer ... interface to the object INSIDE of the object. ...
    (comp.lang.php)
  • Re: A question (confusion) about closure
    ... Local variables have dynamic duration and local accessibility. ... Own/static variables have indefinite duration and local (private) accessibility. ... Closures are just like own/static variables, ... system and each programmer sets up his/her own private sub-domains ...
    (comp.lang.lisp)
  • Re: fields or properties
    ... All you have to do is change the name of the (now private) field, ... manipulated _only_ within the owning class, ... one class and find _all places_ where that field is changed, and modify ... I'm a lazy programmer and I don't like cluttering my brain ...
    (microsoft.public.dotnet.languages.csharp)
  • I am Shocked
    ... Until 6 years ago I was a C++ programmer. ... private double d; ...
    (microsoft.public.dotnet.languages.vc)