"Russell Reagan" <> wrote...
> I think compiler enforced restrictions upon data and functions are a good
> thing, as it reduces the mental complexity of a program.
>
> I ask the question: Could the public, protected, and private access
> descriptors be improved upon?
Whom do you ask?
> I think allowing a class to declare read, write, and execute permissions
for
> other classes and functions to its own variables and functions (much like
> the unix file system, and access control lists) would be a better
> alternative to only having public and private.
Permissions in file systems are run-time features. Access specifiers
in C++ are compile-time features. I am not sure how you manage to
compare them. There are, basically, no classes or members thereof,
during run-time. Hence, there is no need for any permissions.
> An example: If class A only needs to be able to read one variable from
class
> B, then class B can give class A read access to that single variable. In
> C++, you would either have to make class A a friend of B, giving it access
> to everything, or you would have to write a public access routine, giving
> read access to everyone.
Not necessarily. There is a technique where you give access to some
third class from both A and B, which eliminates the necessity to open
access to "everyone".
> I think there should be a happy medium between "one
> gets access to all" (friend), or "all get access to one" (public member
> function).
>
> I think this would make code more intellectually managable, more solid,
and
> more robust, and it could introduce new optimization possibilities for the
> compiler.
OTOH, it would make the system much more complex and much more difficult
to comprehend and maintain.
> First, am I overlooking any way to accomplish this greater level of
> restriction in current standard C++?
Yes, I think so. What you seem to be forgetting is 'const'. Make
a certain variable 'const' and you won't let others to change it.
Kind of "read-only".
> Second, would this actually be an improvement? I've never created a
> programming language, so I could be overlooking important issues.
I am not sure how "execute" would be an improvement. What problem would
it solve that cannot be solved today? As soon as you can demonstrate
that, you can show that it would be an improvement.
> Finally, does a language already exist that has more strict restrictions
> upon data and functions?
If it does, this is not the right place to ask about it. Try
comp.programming.
Victor
|