Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Is typeglob feature really useful? (typeglob references)

by eyepopslikeamosquito (Archbishop)
on Jan 10, 2021 at 02:59 UTC ( [id://11126689]=note: print w/replies, xml ) Need Help??


in reply to Is typeglob feature really useful?

Please use typeglob not glob in future to avoid confusion with the glob function. Perl typeglobs have a notoriously obscure syntax. They are rarely used in high-level user code. They are often used in low level system code and when building tools. Some background and references:

Though I've used typeglobs occasionally, for example in an automated testing hack to verify a file being used by a module contained the expected content, their syntax always does my head in. That I'm no typeglob expert is proved by not finding Ton's famous winning typeglob hack, despite hacking away for a whole week in Christmas 2006. :)

References added later:

  • The Symbol Table Describes Itself: examples comparing Perl, Raku and Python (especially task 2). Note that typeglobs do not exist in Raku because the sigil is part of the name stored in a symbol table, while in Perl 5 the name is stored without the sigil.
  • Test::More - this core module uses a cute typeglob alias (sub isnt { ... } *isn't = \&isnt) allowing you to write isn't in your tests, as an alternative to isnt
  • Dollar Bracket Star ${*...} by snoopyjc (2021)

Updated: Changed title from glob to typeglob in step with xiaoyafeng. Added more examples of typeglobs long after original reply was made.

Replies are listed 'Best First'.
Re^2: Is glob feature really useful?
by xiaoyafeng (Deacon) on Jan 10, 2021 at 09:33 UTC
    Thanks for your reply and sharing. I realize that what I post is not saying typeglob is bad feature, but the current implementation for it decrese performance. maybe that's why raku abandon this feature?




    I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

      I don't know why typeglobs were removed from raku and my google-fu wasn't good enough to find a clear explanation of Larry's rationale for this. However, I did find How naming of variables works in Perl 6 by Elizabeth Mattijsen which states:

      As you may have noticed, Perl 6 does not have a * sigil nor the concept of typeglobs. If you don't know what typeglobs are, you don't have to worry about this. In Perl 6, the sigil is part of the name stored in a symbol table, whereas in Perl 5 the name is stored without the sigil. For example, in Perl 5, if you reference $foo in your program, the compiler will look up foo (without sigil), then fetch the associated information (which is an array), and look up what it needs at the index for the $ sigil. In Perl 6, if you reference $foo, the compiler will look up $foo and directly use the information associated with that key. Please do not confuse the * used to indicate slurpiness of parameters in Perl 6 with the typeglob sigil in Perl 5 -- they have nothing to do with each other.

      To make any sort of case for their removal from Perl 5, you'll need to do more than assert that "the current implementation for it decrease performance". You'll need to prove it by publishing some benchmarks. Given the backward compatibility nightmare that would be unleashed if typeglobs were removed from Perl 5, it seems preferable to me to leave them in the language and instead try to improve their performance. Admittedly, that's not for me to say, I don't have the skills or desire to be a Perl 5 pumpkin. If you feel strongly enough about it, I suggest you publish some benchmarks and discuss on P5P.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found