(Disclaimer: My purpose in proposing this is not to recommend it, but 
to document whether the idea should be endorsed, or shot down, and any 
proposed canonical syntax.  Note that the later implications of these 
choices are quite substantial.  Please discuss!)

[Draft Proposal: Declaring Classwide Attributes]

Within a class, "classwide attributes" are declared using the standard 
"my" and "our".

Example:

        class Zap {
                my %zap_cache;  # a private classwide attribute
                our $zap_count = 0;     # a public classwide attribute

                attr $foo;
                attr $bar;
        }


[Discussion]

Many OO-based languages have the concept of "classwide" attributes; 
that is, attributes that only exist once, for the class (and all 
subclasses?), as opposed to existing one for each instance of a class.  
You can use these attributes as counters, or caches, or any other 
common ground for use by all instances of the class.

Within a class definition, Perl simply uses the my/our keywords for 
this purpose.

If any value is to be assigned to a "classwide" attributes, that 
assignment is done once, upon initialization of the class.

[PROS]

- Obvious utility.  No new syntax introduced.

[CONS]

- ?


[Related Issues, Known Implications]

- This hinges on our definitions of "private" and "public".  "my" vs. 
"our" may in fact mean "private" vs. "protected", or perhaps 
"protected" vs. "public".

- What the heck does "initialization of the class" really mean?  That 
needs to be clearer.


MikeL

Reply via email to