Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: Thx, St. Larry, for the Beauty of Sigils

by LanX (Saint)
on Jul 30, 2019 at 14:30 UTC ( [id://11103625]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Thx, St. Larry, for the Beauty of Sigils
in thread Thx, St. Larry, for the Beauty of Sigils

Just yesterday I had to implement a proxy object which delegates calls to other objects.

getattr() seems to be like Perl's ->can() , but with the difference that you have to check the type in Python by yourself.

IIRC are classes and objects in Python dicts anyway, which can be accessed via __dict__, though w/o inheritence.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^4: Thx, St. Larry, for the Beauty of Sigils
by Eily (Monsignor) on Jul 30, 2019 at 15:06 UTC

    I suppose that by "check the type" you mean try to use the value and hopefully catch the error if it didn't work :P

    I'm not sure what your point is, are you saying that there are cases where the idiom is useful? Sure, so are some of the things strict complains about, that's what no strict is for. But if you only used it for one object, there's a chance you only used the idiom once right? If a language has a syntax that is a little cumbersome for a bad practice that can be useful in some rare edge cases, that's not really a language flaw.

      > I suppose that by "check the type" you mean try to use the value and hopefully catch the error if it didn't work :P

      Python doesn't have separated namespaces for scalar, array, hash or function attributes for classes.

      Perl does have separated slots in a package STASH.

      So ->can() will only return valid coderefs.

      I suppose getattr() returns on them all.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-03-28 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found