> > >>  [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.

Agreed.  In C, the three shifts could be evaluated in several ways:

1:     Shift 1, Shift 2, Shift 3
2:     Shift 1, Shift 3, Shift 2
3:     Shift 2, Shift 1, Shift 3
4:     Shift 2, Shift 3, Shift 2
5:     Shift 3, Shift 1, Shift 2
6:     Shift 3, Shift 2, Shift 1

which is factorial(number of arguments) - although most compilers take the
first approach.  Relying on this order in C is non-portable between
compilers - I've read documentation for one compiler that said it took middle
first (i.e. either 3,4) which is very counter-intutive.

Now, many "Perl" experts will have experience in other languages, such as C
where this is suicidal for portable code.  C doesn't specify order, so that
the order of evaluation can be changed for optimisation.

E&OE

Jonathan Paton

=====
s''! v+v+v+v+  J r e P    h+h+h+h+ !s`\x21`~`g,s`^ . | ~.*``mg,$v=q.
 P ! v-v-v-v-  u l r e r  h-h-h-   !12.,@.=m`.`g;do{$.=$2.$1,$.=~s`h
 E !   v+v+v+  s     k e  h+h+     !`2`x,$.=~s`v`31`,print$.[$v+=$.]
 R !     v-v-  t H a c h  h-       !}while/([hv])([+-])/g;print"\xA"
 L !             A n o t           !';$..=$1while/([^!]*)$/mg;eval$.

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Reply via email to