6 ms·
What good reason is that?
by roryrjb 7y ago
What good reason is that?
- mannykannot 7y agoI still use Perl 5 for some tasks, but my rule-of-thumb is that if I anticipate wanting to use references, I will go elsewhere.
- jerf 7y agoI suggest and use the opposite rule of thumb, "always use references". It tends to simplify things. Python writes the same rule into the language itself.
- mannykannot 7y agoWhen I used it for larger tasks, I did the same. Nowadays, the consequence of my rule is that Perl 5 sits in my toolbox between Awk and Python.
- ether_at_cpan 7y ago> but my rule-of-thumb is that if I anticipate wanting to use references, I will go elsewhere Why? References are not scary and they work just like in any other language -- they are simply a memory address that points to another value stored somewhere else.
- mannykannot 7y agoThe implementation is not the issue; it is the awkward and fussy syntax. It is not a show-stopper -- I coped with it for a while -- but there are better alternatives.
- kbenson 7y agoThe happy-path syntax is pretty straightforward. I wonder if you're under the impression like some that you need to use the arrow syntax or prefixing dollar for every reference, and not just the first? That's not the case. e.g. my @a = ( { first=>1, second=>"b", another_ref=>["y"] }, { first=>1, second=>"b", another_ref=>["z"] }, ); say $a[0]{first}; # Outputs 1 say $a[1]{another_ref}[0]; # Outputs z my $a2 = \@a; # top level is a reference too now say $a2->[1]{another_ref}[0]; # Outputs 1, arrow only needed at top level # The following are alternate syntax that I find unnecessary and better left alone (and most do) say $a2->[1]->{another_ref}->[0]; # Outputs 1, explicit, entirely unneeded because it's unambiguous without extra arrows say $$a2[1]{another_ref}[0]; # Outputs 1, extra prefixing $ dereferences first level ref Personally, I'm happy with a single arrow that lets me know if I have a reference or not. References are important, because they denote that this data may be accessed elsewhere as well, so I'm happy to have a small reminder. Inner level references needing a bit of care if they are copied is somewhat normal though, most non-toy languages have some concept of deep or shallow copying.
- mannykannot 7y agoI rest my case (it is a personal preference, anyway.)
- kbenson 7y agoFair enough. I did go a little overboard in the name of completeness. IT just boils down to actually understanding what a reference is in Perl (which is something that needs to be done for anything non-amateur), and then realizing there's one -> or not depending on if it's a reference (and doing the wrong thing will fail, not do weird stuff). Personally, I like that it forces you to be aware that this data structure is likely in use somewhere else as well, and your changes may not be local (which is true of deeper levels regardless).
- mkozlows 7y agoOff the top of my head: 1. CPAN was great 20 years ago, but it's a joke compared to modern dependency management systems. 2. Functions don't have explicit parameters, and still shift off of @_. (This can be kind of a catch-all for all the "things that are useful for scripts, but suck for programming in the large" design decisions in Perl 5, because I honestly don't remember all of them at this point.)
- jasonjayr 7y agoAs an active perl5 programmer, what do you mean by (1)? To this day, I've seen package management systems for many languages, and none I've seen has been as good as CPAN in terms of (1) Consistent place for distribution + documentation (cpan.org/metacpan.org) (2) Automated testing on a wide variety of platform and configuration (cpantesters.org) (3) CPAN has as standard for declaring dependencies in packages, but a newer "cpanfile" may be more akin go "modern" dependency management. Perl has also had a way of 'use Package $version' right in the source code for ages. (4) the command "cpanm Package::Name" (or even the older "cpan Package::Name") almost always results in figuring out whatever distribution needs to be installed, even if the distribution is named differently from the package name.
- ricardobeat 7y agoI don’t know where you’ve been looking, but none of that is particularly interesting or new at this point. I worked with Perl daily and find CPAN even more of a wasteland than NPM. The average package there hasn’t been updated in a decade and has ancient dependencies to match; takes months / years for clients to be written for new tech.