Re: [PEPr] Comment on RFC::Coding standard enhancements
| From: | Helgi Þormar Þorbjörnsson | Date: | Sat, 08 Mar 2008 13:57:06 +0000 |
| Subject: | Re: [PEPr] Comment on RFC::Coding standard enhancements | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-49334@lists.php.net to get a copy of this message | ||
On 7 Mar 2008 19:15:10 -0000, Paul Jones <pmjones@ciaweb.net> wrote:
>
> Paul Jones (http://pear.php.net/user/pmjones) has commented on the
> proposal for RFC::Coding standard enhancements.
>
> Comment:
>
> I have a suggestion on the "how-to" of splitting long if() conditions. I
> think we should encourage that the conditions be expressed as variables,
> and then use those variables in the if() condition, so as to keep the
> condition set all on one line.
>
>
>
> Given the original example, that would translate into something like the
> following:
>
>
>
> $is_foo = ($condition1 || $condition2);
>
> $is_bar = ($condition3 && $condtion4);
>
> if ($is_foo && $is_bar) {
>
> // ....
>
> }
>
>
>
> This has the benefit of "naming" the condition sets so they are easier to
> distinguish, and splits the different condition sets into readable chunks.
> Doing this should greatly reduce the need for splitting if() condition
> sets
> across multiple lines.
Paul raises a good point, I think we should mention this as one of the
recommended styles for very long if sentences.
Having couple of "best practice" without any real enforcement would be
really nice to have, that way we can tell people to use one of those if in
doubt, pick what you like or propose a new one to be added.
- Helgi