I know I'm jumping ahead, but here goes...

Built-in classes in Perl 5 and 6 are uppercase: UNIVERSAL, ARRAY, HASH, etc.
By convention, "user" classes are Title::Cased.  Simple guideline: don't use
UPPERCASE class names or risk being squished by a later revision of Perl.

Method names *sort of* follow the same convention in Perl 5: DESTROY, FETCH,
STORE, etc.  User-defined methods are usually lowercase().  Simple
guideline: don't use UPPERCASE method names or risk being squished by a
later revision of Perl.

Now Perl 6 has "properties", some of which will be "built-in", from what I
can gather.  Apocalypse 2 says:

    "Note that when you say $foo.bar, you get $foo's compile-time
     property if there is one (which is known at compile time, duh).
     Otherwise it's an ordinary method call on the value (which looks
     for a run-time property only if a method can't be found, so it
     shouldn't impact ordinary method call overhead.)"

Given this, it seems to me (again, possibly jumping the gun) that the entire
lowercase method namespace is "unsafe" since you never know when a new
built-in property will be added to the language.

Say I've got a favorite Perl 6 module that I've been deploying for years,
and the most popular method is foo().  But then Perl 6.0.2 arrives with a
whizzy new built-in "foo" property that I'm just dying to use.  Do I have to
force everyone to check this property with $obj.btw{'foo'}, and warn them
sternly that $obj.foo won't do what they expect?  (Or should they next
expect that? :)  Or do I have to change my favorite module's interface to
accommodate the new property?

And what happens here?

    module My::Class;

    sub .constant { 0 }

    ...

    $foo = My::Class->new(...);

    $foo is constant; # Sets "constant" property, right?

    unless($foo.constant) # Calls .constant() *method*, right?
    {
      # Does it make sense to get here?
    }

This problem already exists to some degree in Perl 5.  Stuff like isa() and
can() is already squatting in the lowercase "user method" namespace.  But I
have a feeling that properties will multiply a lot faster than UNIVERSAL
methods, so the opportunity for conflict seems even greater.

One possible solution it so make all built-in properties UPPERCASE:

    # Set built-in property
    $obj is CONSTANT;

    # Check built-in property
    if $obj.CONSTANT { ... }

    # Call user-defined method
    $obj.constant;

The simple guideline: don't use UPPERCASE property names, or risk being
squished by a later revision of Perl.

I have to admit that UPPERCASE built-in properties strikes me as damn ugly,
but it does avoid namespace conflicts... :-/

IIRC, doing the same thing for built-in/special methods was proposed by one
RFC:

    sub IMPORT { ... }

    if $obj->ISA(...) { ... }
    if $obj->CAN(...) { ... }

Of course, that means you'd also have to do:

    @array.LENGTH
    $fh.NEXT

and so on.  More ugliness.  Hrmmm... :-/

Well, I guess this'll all be covered in the Apocalypse that deals with
objects and modules.  But the property/method namespace conflict is relevant
to Apocalypse 2, IMO, so I'm looking for some answers about that part...

-John

Reply via email to