On Wed, Nov 20, 2002 at 08:46:25PM -0000, Peter Scott wrote:
> [EMAIL PROTECTED] (Steven Lembark) writes:
> >-- Peter Scott <[EMAIL PROTECTED]>
> >> In article <[EMAIL PROTECTED]>,
> >> [EMAIL PROTECTED] (Abigail) writes:
> >>> On Wed, Nov 20, 2002 at 11:42:43AM +0100, Bart Lateur wrote:
> >>>> On Wed, 20 Nov 2002 04:10:02 -0600, Steven Lembark wrote:
> >>>>
> >>>> > sub commify
> >>>> > {
> >>>> > my ( $max, $sep, $end ) = ( shift, shift, shift );
> >>>> ...
> >>>> > }
> >>>>
> >>>> Wow! Hold it! Am I the only one who finds this absurd? More than one
> >>>> shift on the same array in one single expressing, sounds like bad style
> >>>> to me. Comments?
> >>>
> >>> Why is that bad style? Many times when people say it's bad style,
> >>> it's just a case of "beauty is in the eye of the beholder".
> >>
> >> It forces the reader to think about associativity and order of evaluation.
> >> If you've been bitten by unexpected outcomes before you might have to
> >> try it to make sure it does what you think.
> >>
> >> I've used shift, shift before, so I already know. But it would be unfair
> >> to foist on a junior maintenance programmer, IMHO.
> >
> >Associativity?
>
> Of the commas. A suitably paranoid programmer is going to wonder whether
> the results will occur in the expected order if they've not tried before.
> It won't occur to a novice. And an expert will already know. But someone
> in between may wonder.
How does an expert know? You say you know because you have tried it. I
think I know for the same reason, and because I have read the perly.y
and op.c, but I wouldn't want to stake anything particularly important
on it.
Can anyone point to any documentation which describes the order of
evaluation within a list? The order of evaluation for the comma
operator in a scalar context is explicitly defined (which is just as
well), but I can't find such a guarantee in list context, which seems
strange if there were such a guarantee, since it would likely be found
immediately after the guarantee for scalar context in perlop. Neither
can I find any tests for this, but I can find one core module which
depends on this left to right order of evaluation.
I suspect this order is unlikely to change because
a. Perl tries hard to DWIM, and left to right is probably what most
people mean.
b. Perl tries hard to be backwards compatible, even when people have
done things that they probably shouldn't have.
There are no guarantees on the order of evaluation within an expression.
Are there within a list?
--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net