Language design: exposed and read only...

"n!" <nfactorial@btopenworld.com>
13 Oct 2002 16:35:54 -0400

          From comp.compilers

Related articles
Language design: exposed and read only... nfactorial@btopenworld.com (n!) (2002-10-13)
Re: Language design: exposed and read only... kgw-news@stiscan.com (2002-10-18)
| List of all articles for this month |
From: "n!" <nfactorial@btopenworld.com>
Newsgroups: comp.compilers,comp.lang.misc
Date: 13 Oct 2002 16:35:54 -0400
Organization: BT Openworld
Keywords: design, question
Posted-Date: 13 Oct 2002 16:35:54 EDT

Hi all,
                For a home research project I'm attempting to write a
compiler/vm, of which I'm still very early in the development stage. I
have the basic structure I'd like for the language (a concoction of
C#, C++, Java and a hint or two of VB amongst others). One thing I've
been thinking about is access privilege levels for class members.


I was thinking along the lines of the following:


private access, members are not accessible from anything outside of its
owning object. This includes objects of the same type. So for example:


class MyObject extends Object;


private int myValue;


public void TestMethod( MyObject other )
{
        myValue = other.myValue;
}


This would fail in my current design as 'other' isn't the same class as the
current object (even if 'other' is actually the same object (ie.
TestMethod( self )). I've been thinking sometimes you do want to access
other objects of the same type (eg. For a copy operation). My thinking has
led onto possibly setting default access to readonly, so the above would
succeed but the following would fail:


public void TestMethod( MyObject other )
{
        other.myValue = myValue;
}


As you cannot write to a private member of a different object (of course,
private members are inaccessible from objects of a different type).
Similarly, public members would be accessible from objects of another type
but as read only. To allow for writeable members I could add an 'exposed'
access level. so:


class MyObject extends Object;


exposed private int myValue;


public void TestMethod( MyObject other )
{
        other.myValue = myValue;
}


Would succeed, and to allow public writeable members you should declare them
as 'exposed public'. Of course, read/write access could be the default and
parameters could be specified as const to support the above format, but I'd
rather keep the amount of times const 'needs' to be written (current
thoughts are that non-exposed/read-only is required more often than
exposed/read-write access).


As I've said, this is all still very early on (I've only just started the
semantic\symbol table phase for the basic language) but I was wondering if
any previous research (or anyones thoughts) could suggest if this was a
'good'\'nice' idea or bad. I'm also not sure if this is the correct forum
(after all this is a language design question rather than compiler writing)
but don't know of any others that suit this topic better (or would have such
a wide range of experience).


Many thanks for any thoughts,
n!


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.