Re: [PATCH v2 00/10] send-email: various optimizations to speed up by >2x
- From
Felipe Contreras <felipe.contreras@gmail.com>
- Date
- May 30, 2021, 16:07 UTC
- Message-ID
- <60b3b84967a62_b937208c@natae.notmuch>
- In-Reply-To
- <877djg313c.fsf@evledraar.gmail.com>
Ævar Arnfjörð Bjarmason wrote:
Show 37 quoted lines
>
> On Sat, May 29 2021, Felipe Contreras wrote:
>
> > Ævar Arnfjörð Bjarmason wrote:
> >>
> >> On Fri, May 28 2021, Felipe Contreras wrote:
> >>
> >> > Ævar Arnfjörð Bjarmason wrote:
> >> >> Returning a flattened list is idiomatic in Perl, it means that a caller
> >> >> can do any of:
> >> >>
> >> >> # I only care about the last value for a key, or only about
> >> >> # existence checks
> >> >> my %hash = func();
> >> >
> >> > I was staying on the sideline because I don't know what's idiomatic in
> >> > Perl, but Perl and Ruby share a lot in common (one could say Perl is the
> >> > grandfather of Ruby), and I do know very well what's idiomatic in Ruby.
> >> >
> >> > In perl you can do $ENV{'USER'}, and:
> >> >
> >> > while (my ($k, $v) = each %ENV) {
> >> > print "$k = $v\n";
> >> > }
> >> >
> >> > Obviously it's idiomatic to use hashes this way [1].
> >>
> >> For what it's worth idiomatic/good idea and "has an example in the perl
> >> documentation" unfortunately aren't always aligned. A lot of experienced
> >> Perl programmers avoid each() like the plague:
> >> http://blogs.perl.org/users/rurban/2014/04/do-not-use-each.html
> >
> > Perl is an old language, and each() was introduced in 2010, it's
> > expected that some old-timers would not adapt to the new idioms.
>
> each() has been in Perl since 1987 with perl v1.0, you must be confusing
> it with something else.I see. I read the each() documentation [1] too hastily:
When called on a hash in list context, returns a 2-element list consisting of the key and value for the next element of a hash. In Perl 5.12 and later only...
> In any case, the recommendation against it has nothing to do with its > age, it's that similar to strtok() it has global state.
Yes, that's what I understood from the blog post you shared, but at least personally I never assume I can modify a hash like that. I see why some people need to be careful with it, but "avoid it like the plague" seems way too defensive programming to me.
[1] https://perldoc.perl.org/functions/each
-- Felipe Contreras