Re: [Vala] enum access modifiers



Good point, in general private inside nested classes or namespaces is a
no-op in the same project.
The only thing that makes a difference is the internal modifier (which is
also the behavior of private) when creating libraries: the resulting vapi
and header files will not have that symbol.

On Sat, Dec 6, 2014 at 3:51 PM, Al Thomas <astavale yahoo co uk> wrote:


  ------------------------------
 *From:* Luca Bruno <lethalman88 gmail com>
*Sent:* Saturday, 6 December 2014, 14:27
*Subject:* Re: [Vala] enum access modifiers

Nested classes or whatelse type is always "static" from a Java view point.
So you access those enum values with test.a.TEST. There's no way those
types can be tied to a particular instance of the parent class.


Thanks for the reply. It was more the use of the 'private' keyword and by
extension the 'protected' keyword that I was trying to understand. For
example:

void main(){
        //var aa = new test();
        print( test.a.TEST.to_string ());
        }

class test: Object {
        private enum a {
                TEST
                }
        }
will compile and run without any errors. But Vala allows an access
modifier for the enum, so should the use of 'private' above, instead
produce a compile time error such as "Access to private member `test.a'
denied"?




I could not understand the rest of the mail, sorry.



On Sat, Dec 6, 2014 at 3:21 PM, Al Thomas <astavale yahoo co uk> wrote:

The Vala manual states that an enum takes an access modifier, from
https://wiki.gnome.org/Projects/Vala/Manual/Enumerated%20types%20%28Enums%29
:"enum-declaration:
 [ access-modifier ] enum qualified-enum-name { [ enum-members ] }"
The following compiles and runs with Vala 0.26.0.33:

void main(){
        var aa = new test();
        print( aa.a.TEST.to_string ());
        }

class test: Object {
        private enum a {
                TEST
                }
        }

and only gives a compilation warning about static
members:"private_enum.vala:3.9-3.12: warning: Access to static member
`test.a' with an instance reference
    print( aa.a.TEST.to_string ());"
So it would appear the current implementation for enums is that they are
public and static. So is this an implementation bug because the access
modifier is ignored or a documentation bug because access modifiers for
enums aren't that useful?
What has brought this on is a patch adding the 'protected' access modifier
to the Genie parser - https://bugzilla.gnome.org/show_bug.cgi?id=690848
Generally I would say the 'public', 'private' and 'protected' access
modifiers allow a public interface for using and extending a class to be
defined a bit more clearly. So implementation details can be hidden with
'private', but also allowed to be extended with 'protected'. While 'public'
provides the accessible API. In that sense enum, as well as struct and
delegate, can be implementation details where access can be restricted.
Enum, struct and delegate are all type definitions so probably should not
be modifiable by a class sub-type, but readable so they can be accessed for
creating a variable of the right type. The patch has also highlighted that
'interface' has an access modifier. Surely an interface should always be
public? Although a method within an interface could possibly be protected
as a mixin for implementation only?
Any thoughts?
Al Thomas


_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list




--
NixOS Linux <http://nixos.org/>





-- 
NixOS Linux <http://nixos.org>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]