Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Unifying namespaces of @name and $name to simplify dereferencing?

by shmem (Chancellor)
on Mar 22, 2016 at 14:26 UTC ( #1158502=note: print w/replies, xml ) Need Help??


in reply to Unifying namespaces of @name and $name to simplify dereferencing?

Are there any pitfalls I didn't think of regarding this hypothetical feature?

This would allow either the association of $identifier with @identifier or %identifier, but not both. To allow both, hashes and arrays have to collapse into one data structure, which is what php does. I personally detest this particular php feature. Associating both makes sigils meaningless imho and kicks you back into C where an identifier can hold an address or a pointer to anything including a function, making it impossible to grasp at first glance what the identifier is about. But this is one of the very reasons sigils denoting variable types were introduced in perl (borrowing that from basic) - which makes your suggestion going against the camel's hair, IMHO.

It would make a good perl-critic rule to disallow the use of the same identifier for different purposes, though.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^2: Unifying namespaces of @name and $name to simplify dereferencing?
by LanX (Archbishop) on Mar 25, 2016 at 19:37 UTC
    Hello Shmem

    Thanks for meditating! =)

    > This would allow either the association of $identifier with @identifier or %identifier, but not both

    yes I was sloppy with the "vice versa" part in my OP.

    > To allow both, hashes and arrays have to collapse into one data structure,

    No, no, no that is not my intention.

    Perl has the advantage that $identifier is an universal untyped scalar which can hold any string, number or reference.

    I'm understanding now that for the reverse direction (assigning a ref) we'd need a declaration clarifying the type, this could be

    my $identifier[] = [1,2,3]

    and/or

    my \@indentifier = [1,2,3]

    , both¹ with the same effect of aliasing $indentifier to \@indentifier

    So using something like

    my ( $name, \@name, \%name ) = @_
    would cause 2 redeclaration errors at compile-time because $name is already taken, so no need for a unifying data structures like in PHP, it's just an aliasing trick to simplify syntax of common data structures.

    Besides this opens the possibility of run-time checking of assigned data types and consequently further OP-code performance optimizations.

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

    ¹) not sure about the best syntax, but both possibilities can't conflict with older code because they are illegal ATM.

    ... Other suggestions?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2019-11-13 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (68 votes). Check out past polls.

    Notices?