Subject: Re: [PATCH v2 00/10] send-email: various optimizations to speed up by >2x

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Sun, 30 May 2021 13:33:31 +0200

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.

In any case, the recommendation against it has nothing to do with its
age, it's that similar to strtok() it has global state. So e.g. you
can't safely iterate over a hash you're modifying with it, or if you
iterate over a top-level structure and pass that variable down to
another function, and it also uses each()...