Re: Bad Code (was: Re: [PHP] ++ BUG??)

From: Date: Sun, 26 Nov 2000 05:42:38 +0000
Subject: Re: Bad Code (was: Re: [PHP] ++ BUG??)
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-27239@lists.php.net to get a copy of this message
> I really do hate to continue this thread, but I don't necessarily agree with > the "bad code" part. Compilers and interpreters can treat them very > differently. I think we can put this to bed. His code was basically $i=($i++)%2. I *think* what he meant was $i=($i+1)%2. those two are certainly not equivalent, you're right. I didn't meant to imply that they were. Assuming he really meant $i=($i++)%2, it would be much more clear (at least to me and I suspect most people) if it were written: $i = ($i % 2) + 1; anyone familiar with the % operator can look at that and see exactly what will happen. The same is certainly not true of $i=($i++)%2, which made me go crosseyed for a few seconds :) And the bug is avoided.

« previous php.general (#27239) next »