in reply to Re^4: Benefits of everything is an object? Or new sigils?
in thread Benefits of everything is an object? Or new sigils?

and your polluting your namespaces...
... and here autoboxing doesn't help a lot. Suppose you have autoboxing, and you use that to define @employees->list_active. That means nothing else can define a list_active that acts on arrays1. That's namespace pollution as well, and IMO, hardly better than namespace pollution by exporting functions.

1Of course, one might say "what are the chances someone else is going to define a list_active?", but if that's true, there aren't worries about name space pollution.

Replies are listed 'Best First'.
Re^6: Benefits of everything is an object? Or new sigils?
by LanX (Saint) on Mar 03, 2010 at 15:50 UTC
    Of course! Changing the autobox is comparable to messing with CORE:: or UNIVERSAL:: in Perl or changing the prototype of Array() in JS.

    That wasn't my point... I was talking about design decissions an cleaner syntax.

    If it's unclear if you will be going to bless or tie a _specific_ primitive array into a class and you wanna stay flexible you will have to use references right from the beginning:

    And this will force you into to sigil accrobatics like writing things like  push @$ref,"elem"

    In this case - i.e. only when dealing with primitives - it's an option to use  $ref->push("elem") right from the beginning to have a cleaner syntax. (The resulting caveates like speed punishment are listed in the OP.)

    But IF you decide later to extend this class you can _bless_ $ref into a new class with list_active -method, without changing the interface you used and without poluting other arrays.

    Anyway my prefered - "utopic" - syntactic solution is to have an extra special sigil for arr_refs, such that you can still write push €ref,"elem" (or even €ref->push("elem") according to your taste) without sigil accrobatics.

    This (and other syntactic simplications) would make Perl5 much easier to use and to learn without breaking compability to older sigils. (And would build a migration bridge to Perl6) Perl forces you anyway to use refs in bigger programs, IMHO there is no big point of @ and % if you can't use them to distinguish the underlying structures.

    BTW: > @employees->list_active

    shouldn't be possible ... neither with autobox nor blessing, you will have to write something like

    \@employees->list_active

    Cheers Rolf

      BTW: > @employees->list_active

      shouldn't be possible ... neither with autobox

      According to the autobox manual, it is possible:
      Values beginning with the array @ and hash % sigils are passed by refe +rence, i.e. under the default bindings: @array->join(', ') @{ ... }->length() %hash->keys() %$hash->values() are equivalent to: ARRAY::join(\@array, ', ') ARRAY::length(\@{ ... }) HASH::keys(\%hash) HASH::values(\%$hash)
        Interesting ...thx.

        (... I can't tell if I like this extra feature or not ... ?)

        Cheers Rolf