Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^6: Declaring with my, assigning, and testing in same line (attributes)

by LanX (Sage)
on Dec 13, 2015 at 19:39 UTC ( #1150178=note: print w/replies, xml ) Need Help??


in reply to Re^5: Declaring with my, assigning, and testing in same line (attributes)
in thread Declaring with my, assigning, and testing in same line

Interesting...

I had the model for CODE attributes in mind which happen at compile time:

(excerpt from attributes )

3. Code: package X; sub foo : lvalue ; Effect: use attributes X => \&foo, "lvalue";

That's why Attribute::Handlers is putting such emphasis onto the compilation phase when the association happens.

but LEXICAL attributes seem to call import with each declaration at run-time (which is consistent with the fact that my has a compile and a run-time effect.)

2. Code: package Felis; my $cat : Nervous; Effect: use attributes (); attributes::->import(Felis => \$cat, "Nervous");

maybe Attribute::Handlers should be clearer about this?

> There are ways how not to be wrong.

(A disturbance in the Force happens)

Now more potential in using attributes I see ... ;-)

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

update

) to be more specific ... this behaviour means that the untie happens almost immediately after the tie, i.e. the potential for possible ugly side effects is practically zero.

Replies are listed 'Best First'.
Re^7: Declaring with my, assigning, and testing in same line (attributes)
by choroba (Archbishop) on Dec 15, 2015 at 09:44 UTC
    this behaviour means that the untie happens almost immediately after the tie, i.e. the potential for possible ugly side effects is practically zero.
    My benchmarks show attributes are much slower than a (&;@) sub, especially for short lists (many thousand times).
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      > are much slower

      Did you expect otherwise? :)

      That's normally the prize for syntactic sugar...

      I wouldn't be surprised if Attribute::Handlers is to be blamed for a big part of the delay.

      Using attributes directly might speed up things, but it will still be considerably slower.

      But when used in the context of debugging or similar speed wouldn't matter that much.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1150178]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2022-08-20 03:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?