Improvement to C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Russell Reagan

    Improvement to C++

    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?

    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.

    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. 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.

    First, am I overlooking any way to accomplish this greater level of
    restriction in current standard C++?

    Second, would this actually be an improvement? I've never created a
    programming language, so I could be overlooking important issues.

    Finally, does a language already exist that has more strict restrictions
    upon data and functions?


  • Victor Bazarov

    #2
    Re: Improvement to C++

    "Russell Reagan" <rreagan@attbi. com> wrote...[color=blue]
    > 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?[/color]

    Whom do you ask?
    [color=blue]
    > I think allowing a class to declare read, write, and execute permissions[/color]
    for[color=blue]
    > 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.[/color]

    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.
    [color=blue]
    > An example: If class A only needs to be able to read one variable from[/color]
    class[color=blue]
    > 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.[/color]

    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".
    [color=blue]
    > 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,[/color]
    and[color=blue]
    > more robust, and it could introduce new optimization possibilities for the
    > compiler.[/color]

    OTOH, it would make the system much more complex and much more difficult
    to comprehend and maintain.
    [color=blue]
    > First, am I overlooking any way to accomplish this greater level of
    > restriction in current standard C++?[/color]

    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".
    [color=blue]
    > Second, would this actually be an improvement? I've never created a
    > programming language, so I could be overlooking important issues.[/color]

    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.
    [color=blue]
    > Finally, does a language already exist that has more strict restrictions
    > upon data and functions?[/color]

    If it does, this is not the right place to ask about it. Try
    comp.programmin g.

    Victor


    Comment

    Working...