LWN.net Logo

Perl far from dead, more popular than you think (Royal Pingdom)

Perl far from dead, more popular than you think (Royal Pingdom)

Posted Nov 10, 2009 0:30 UTC (Tue) by alankila (subscriber, #47141)
In reply to: Perl far from dead, more popular than you think (Royal Pingdom) by chromatic
Parent article: Perl far from dead, more popular than you think (Royal Pingdom)

I just think it's plainly unfortunate that @ and % still exist, given that all that you could have got with them is now doable with references and the corresponding constructors of those structures. So imagine that newbie documentation only said:

@foo = (1,2,3); # depreciated
$foo = [1,2,3]; # endorsed.

Unfortunately the syntax for references then gets a few annoying {} and -> which the @ and % versions can avoid, so stuff that should be simple looks ugly as heck.

I agree with the base criticism of the grandparent: everyone learning Perl5 will have to climb that particular roadblock of untangling the rather subtle meaning of "@a = (1,2,3)" and then the completely different "$a = [1,2,3]".


(Log in to post comments)

Perl far from dead, more popular than you think (Royal Pingdom)

Posted Nov 10, 2009 2:16 UTC (Tue) by chromatic (guest, #26207) [Link]

PHP tried single-sigil variables; it works about as well there as does making all arrays associative (not indexed). The semantics are messy when you do anything non-trivial and you actually *lose* type information when reading code.

I think you also break list context and complicate the optree, when you can't determine at compilation time if a list is constant or if it's merely part of an array constructor.

Perl far from dead, more popular than you think (Royal Pingdom)

Posted Nov 10, 2009 6:34 UTC (Tue) by alankila (subscriber, #47141) [Link]

Well, Perl references go $foo->[] and $foo->{} for the two kinds we have in mind here. They are clearly distinct and no information is lost by not having @ and % visible in this expression.

That being said, it's a bit frustrating if you would need some third kind of collection, there's no syntax available for that. But that's a completely different argument, and my opinion is that there's no real need to use every symbol on the keyboard, anyway: a single generic syntax seems cleaner to me than allocating every type of brace for something. Java only has fixed-size arrays available on syntactic level and no hashes at all: method calls work as the generic extension mechanism. PHP apparently decided to just implement arrays as hashes and forget about having "real", numerically indexed arrays.

As to the second point, I'm not even proposing removal of anything, I was just suggesting that the @foo and %foo style variables could/should be avoided as unnecessary in new code.

On a tangential note, here's another of these famous Perl hacks which indicates that Perl currently plays fast-and-loose about which lists are constants and which are not:

$ perl -wle 'sub bug { print map $_++, 1..3; } bug(); bug()'
123
234

For some reason this never bites anyone, allegedly.

Copyright © 2012, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds