Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by LanX (Saint)
on Jul 26, 2019 at 19:55 UTC ( [id://11103477]=note: print w/replies, xml ) Need Help??


in reply to Thx, St. Larry, for the Beauty of Sigils

Just to be sure I understand the problem.

because a variable is a bareword you can't just type ?

meth = "name" obj.meth()

In JS you could solve this with a bracket syntax to look up an attribute obj[meth]()

Console demo:

> obj = { name : function () {return "called" } } Object { name: name() } > meth ="name" "name" > obj[meth]() "called"

But in python you need a function getattr() ?

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^2: Thx, St. Larry, for the Beauty of Sigils
by daxim (Curate) on Jul 29, 2019 at 08:56 UTC
    Yes, but the bracket subscript trick works for dynamic class names, thus: globals()["CLASSNAME"] 🤢

    I wrote about this before at http://redd.it/6epqi5#did1j9b and I also have a collection for several programming languages at https://stackoverflow.com/q/26402047. ES6 classes are missing, and eval('CLASSNAME') is the answer.

    tl;dr if the language does not have sigils on identifiers, this topic is a pain in the butt.

      I like sigils, probably also because my first language was BASIC.

      But I still think they make code more readable, kind of Hungarian Notation

      Parsing non sigil languages is hard without syntax highlighting. *

      And isn't readability part of the Zen(terfold) of Python? ;)

      But some things are unfortunately solved in Perl 5.

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

      *) On a side note: I remember having problems with English too, where the same word can sometimes be a verb, adjective and noun, where other languages have grammatical suffices.

      Headlines in the English newspapers are still a riddle...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-04-24 10:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found