develooper Front page | perl.perl5.porters | Postings from February 2015

[perl #123898] [PATCH] Modernize the second part of perldsc.pod.

Thread Previous | Thread Next
From:
Shlomi Fish via RT
Date:
February 26, 2015 07:38
Subject:
[perl #123898] [PATCH] Modernize the second part of perldsc.pod.
Message ID:
rt-4.0.18-31449-1424936301-1221.123898-15-0@perl.org
On Wed Feb 25 19:17:45 2015, perl.p5p@rjbs.manxome.org wrote:
> * Shlomi Fish via RT <perlbug-followup@perl.org> [2015-02-25T04:27:55]
> > On Sat Feb 21 14:34:24 2015, aristotle wrote:
> > > Uh, every iteration of the inner loop is spared the lookup of
> > > $AoA[$i].
> > >
> > > However, while I *would* perform this refactoring on real code, I
> > > find
> > > it a change for the worse in this instance in that it conceals the
> > > correspondence between the structure of the code and the data
> > > structure.
> >
> > I see - well, I'll wait for a consensus or veto here.
> 
> I am with Aristotle.  While I'd make the change in product code, I
> think the
> documentation is better as written for the purposes of demonstration.
> 

Very well, then, I'll change it back.

> > > + LINES:
> > >   while ( <> ) {
> > > -     next unless s/^(.*?):\s*//;
> > > +     next LINES unless s/^(.*?):\s*//;
> > >
> > > (Repeat some two dozen times.)
> > >
> > > I cannot find a single case where this helps comprehension. It just
> > > adds
> > > noise. Every single time.
> >
> > I added the LINES label per the best practice of
> > http://perl-begin.org/tutorials/bad-elements/#flow-stmts-without-
> > labels
> > (which also appears in the book Perl Best Practices). If there's a
> > consensus
> > or a veto that it shouldn't be added, then I'll remove it in the
> > redone
> > patch.
> 
> Here, I'm not with Aristotle except in the practical outcome.  I
> nearly always
> use this pattern, as I find it practical when doing later refactoring
> (but not
> because of skimmability).  On the other hand, I would not change the
> documentation.  I think it's clearer without the label.  There is less
> to take
> in without it.

OK.

> 
> > > The added `my`s are fine, but consider the “after” version. If you
> > > have
> > > just declared @tmp inside the loop body to hold the return values
> > > of
> > > a function call, why then flatten it in an anonymous array
> > > constructor,
> > > which makes a copy of its contents? Just take a reference to it:
> > >
> > > for my $i ( 1 .. 10 ) {
> > >     my @tmp = somefunc($i);
> > >     $AoA[$i] = \@tmp;
> > > }
> >
> > Code like that (= declaring a lexical aggregate variable and storing
> > a
> > reference to it in a container variable) is exactly what the text
> > that I
> > removed from the previous patchset to perldsc.pod warned against
> > doing (and I
> > thought such a warning was no longer necessary in this day and age).
> > So what
> > is the verdict regarding doing it?
> 
> I had a flip through the history on that file and I couldn't find what
> you're
> referring to — but to be fair, I gave up pretty fast.  If we know that
> @tmp is
> quite local to the loop, which we do, I'd do what Aristotle
> recommends.
> 
> Is your previous change relevant to that?  If so, could you point it
> out to me?

Sorry, that was an awkward phrasing on my part. I meant that I wanted to remove a paragraph which warned about doing exactly that and that it was considered still relevant, and was vetoed against. I'm referring to:

[QUOTE]

 That's because my() is more of a run-time statement than it is a
 compile-time declaration I<per se>.  This means that the my() variable is
 remade afresh each time through the loop.  So even though it I<looks> as
 though you stored the same variable reference each time, you actually did
-not!  This is a subtle distinction that can produce more efficient code at
-the risk of misleading all but the most experienced of programmers.  So I
-usually advise against teaching it to beginners.  In fact, except for
-passing arguments to functions, I seldom like to see the gimme-a-reference
-operator (backslash) used much at all in code.  Instead, I advise
-beginners that they (and most of the rest of us) should try to use the
-much more easily understood constructors C<[]> and C<{}> instead of
-relying upon lexical (or dynamic) scoping and hidden reference-counting to
-do the right thing behind the scenes.
+not!
 
[/QUOTE]

And now I was told to convert the code to do exactly that.

So what should we do?

Regards,

-- Shlomi Fish

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=123898

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About