develooper Front page | perl.perl5.porters | Postings from January 2001

Re: Multiple post(inc|dec)rement

Thread Previous | Thread Next
Nicholas Clark
January 17, 2001 06:56
Re: Multiple post(inc|dec)rement
Message ID:
On Wed, Jan 17, 2001 at 02:39:52PM +0000, Simon Cozens wrote:
> On Wed, Jan 17, 2001 at 02:21:34PM +0100, Johan Vromans wrote:
> > Stephen McCamant <smcc@CSUA.Berkeley.EDU> writes:
> > 
> > > IMHO, pp_pre(inc|dec) were written the way they are now for a reason
> > > (namely efficiency), and it isn't worth slowing them down just to make 
> > > some pathological examples more intuitive.
> > 
> > And, my dear Stephen, how much is the slowdown for an average Perl
> > program?
> I'm of the opinion that if people think that writing
>     (++$a, ++$a)
> is a good idea, then they're fundamentally confused anyway. Slowing
> Perl down isn't going to unconfuse them.

I don't agree that they are confused.
C has a documented concept of "undefined" (and a spec)

perl only has implementation defined behaviour, and no comprehensive spec.

for $a=2
(++$a, ++$a) could easily mean 2 things

(3, 4)

if I assume that arguments get evaluated left to right (not an unreasonable
assumption, but if people should not make this we need to document it)

(4, 3) or (3, 4)

if I assume that argument get evaluated in some order. I'm not worried what
that order is, but I am assuming that one is fully evaluated before the
other's evaluation starts.

However, (4, 4) isn't intuitive, unless you are a *good* C programmer.
[bad C programmers will assume one of the above]

Nicholas Clark

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About