On Wednesday, October 9, 2002, at 07:54 PM, Chris Dutton wrote:
> One first thing I notice while I'm supposed to be doing homework. :-)
>
> Wasn't "class MyClass;" supposed to work along the line of Perl5's
> "package MyClass;" and make everything following that statement the
> definition of MyClass?
Yeah, I think so too, but don't know for sure. The "class MyClass"
would mirror "sub" declarations, allowing you to make anonymous
classes, assign properties to classes, etc. The package-style "class
MyClass;" would work, um, just like packages.
One reason I can think of to choose the first instead of the second
would be if you wanted properties (or parent classes!) to be able to
alter the grammar of an individual class, which would be a neat way to
tack different OO zealotry onto a class without enforcing it on others:
class MyClass is wackyGrammar {
...
}
vs.
{
class MyClass;
...
use wackyGrammar;
}
.... there would be a minor problem because you've already entered the
"grammar" of a class by the time you get to the 'use' . (A hybrid
approach, a packagelike "class MyClass is wackyGrammar;" would also
work, tho.)
In theory, *both* could be made to work with little effort. I think it
depends on how much we want to treat classes like packages, vs. classes
like objects. I arbitrarily chose to put the non-package example in
because it was more likely to provoke counterexamples. ;-)
MikeL