Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Is glob feature really useful?

by LanX (Saint)
on Jan 09, 2021 at 18:32 UTC ( [id://11126664]=note: print w/replies, xml ) Need Help??


in reply to Is typeglob feature really useful?

(I moved this to meditations)

First of all your wording is dubious, (type)globs are only used with our package variables. Private variables with my don't have any type-globs. (which leads to some break in orthogonality)

The origin of type-globs (i.e. "things" with sigil * ) lies IMHO in Lisp, which has similar Symbol Tables.

Obviously it's possible to have separated name-spaces with sigils.

So are you asking to abandon sigils?

It's true that many think that using the same name aka symbol for different types is bad style.

But I see no way to stop using sigils in Perl, since all the context mechanics would stop working.

Any changes on that level would lead to a Perl6'ish compatibility mess (well probably even worse).

And * is needed for exporting functions into other namespaces.

HTH! :)

PS: Though I could imagine a pragma which automatically declares $xxx = \@xxx after a my @xxx (analogous for $yyy = \%yyy ), this would facilitate reference mechanics a lot. This pragma would automatically forbid name reusing (mostly) and referencing and dereferencing with \ and -> would become mostly unnecessary.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

update

I forgot to mention, every fancy feature comes with a price. In languages like JS or Python name-collisions are a quite common trap.

For instance if you assign to a variable list when the function/method list already exists.

And equally named nouns and verbs are quite common in English due to it's simplicity of grammar.° (e.g. compare noun Liste vs verb listen in German)

This is never a problem in Perl! $list will never collide with &list ....

°) a funnier example Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo

Replies are listed 'Best First'.
Re^2: Is glob feature really useful?
by xiaoyafeng (Deacon) on Jan 10, 2021 at 09:23 UTC

    So are you asking to abandon sigils?

    ehh no, sigil is the spirit of perl. no sigils no perl. what I mean is perl allows a same name but different type. and It's also a good feature but perl sacrificed much performance for it.

    for support this feature, perl have to create a 6elments hash to store one name. see below:
    like a package scalar variable: $FOO = '123'; actually store: *Foo{SCALAR => '123', HASH => '', ARRAY =>'', GLOB => '', PACKAGE => ' +', NAME =>''},
    If we discard above feature, we could store a scalar on STASH directly. To me it's more understandable and maybe faster.




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

      That's only the case with our variables and subs.

      Package variables are the exception and sub lookup is optimized AFAIK.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found