Re: Re: Wrapping long if statements
| From: | Justin Patrin | Date: | Tue, 16 Nov 2004 19:29:57 +0000 |
| Subject: | Re: Re: Wrapping long if statements | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-34417@lists.php.net to get a copy of this message | ||
On Tue, 16 Nov 2004 13:22:49 -0500, Philippe Jausions
<philippe.jausions@11abacus.com> wrote:
> Jesper Veggerby Hansen wrote:
>
>
> > Hi Guys,
> >
> > Been looking a bit on CS and was wondering how you would wrap a very
> > long if-statement (line-length) while still maintaining readability. Fx.
> >
> > if (($a == 0) and ($b == 0) and ($c == 0) and ($d == 0) and ($e == 0)) {
> > // do something
> > }
> >
> > I think if you wrap it to something like this it makes it a lot less
> > readable since the indention of the conditions are the same as the
> > statements to within the if-statement, i.e.:
> >
> > if (($a == 0) and ($b == 0) and ($c == 0) and
> > ($d == 0) and ($e == 0)) {
> > // do something
> > }
>
> I like doing:
>
> if (($a == 0) && ($b == 0)
> && ($c == 0
> || $d != 0)
> ) {
> // do something
> }
>
> That is, putting the operand at "start" of line and indenting for more
> complex sub-expression, so grouping is visually easy to spot.
>
I also put the operand at the beginning, but I go a bit further. When
I break up the conditions I put *every* condition on its own line (at
least at the same level) to make it even easier to read:
if (($a == 0)
&& ($b == 0)
&& ($c == 0
|| $d != 0)) {
// do something
}
--
Justin Patrin