I agree that this approach is deranged. It all stems from the decision to distinguish between values and references. That decision comes from the available hardware and typical programming background at the time of Perl 5's development (early 90s). At that time computers weren't abundantly fast for most programming goals, and storing all variables as references (or objects) was a pretty serious "extreme OO" position. Plus, anyone who called himself a hacker would have to be competent with pointers in C, and Perl references were substantially easier than that. So Perl layered on ways to reference and dereference values, and @{$array->[1]{"foo"}} was born.
You really believe that? I simply can't believe anyone would find working with complex data structures in C easier than in Perl. It just doesn't make sense, but obviously a few people agree with you. Have you actually worked in Perl (and C)?
C pointers make sense to me because they represent what's going on in the machine. The syntax and the rules behind it are simple enough that they click, for me.
Perl references seem to carry a lot of historical baggage that leads to the expressions mentioned elsewhere in this thread. The rules behind them always seemed arbitrary and I have never felt like I had a grip on them.
Now that said, I'm still more likely to blow my foot off with C than with Perl, thanks to the do-it-yourself memory management. But at least when it happens it's for the right reasons.
Now that said, I'm still more likely to blow my foot off with C than with Perl, thanks to the do-it-yourself memory management. But at least when it happens it's for the right reasons.
You're my hero, and I mean that.
I'm glad we cleared that up, and I'll readily agree that complex data structures via references is among the most glaring warts in Perl. It's obviously more complicated and error-prone than it ought to be, and moreso than other similar languages.
I've got this theory that the thing that people talk about most in any language or technology is the thing that is actually most broken about the language. People talk a lot about references in Perl, and I know they're broken by design. Similarly, I've got my suspicions about monads in Haskell, since people spend so much time trying to explain them...seems like there must be some fire under all that smoke. But I could be just imagining it, and I think I probably need to spend a lot more time with Haskell before I can accurately detect bogosities.