in reply to bloated 'if' formatting

I fairly recently (months ago) finally stumbled upon an indentation format that I actually liked for conditionals, instead of the many different ones that I'd used over the years that all didn't work well in some situations (didn't "scale" well). I've had the chance to use it for a large variety of situations and I like it even more.

It is mostly the same as what appears to be the most common style in this thread. The possible difference is when you have more complex expressions. I like spacing to make code easier to understand. I try to avoid complex conditional expressions, by breaking them up when possible. But, sometimes, a fairly complex expression makes sense (especially when you want a chain of elsifs, which makes splitting up a conditional more distruptive to the flow).

Here is a fairly worst-case example (based on actual code):

} elsif( StatusEvent::CONNECT_FAILED == $status->GetStateTransition() && CONNECT_TYPE_AUTO != $status->GetConnectType() || StatusEvent::DISCONNECTED == $status->GetStateTransition() && ( $IsAutoConnectDisabled || 0 == $statusNotAuto->GetTotalCount() ) && $statusNotAuto->GetTotalCount() == statusNotAuto->GetIdleCount() ) {

The indentation makes it easy to successively break down the expression. You can see the two main chunks of the expression separated by the left-most ||. Looking at each chunk, you see the two or three chunks separated by &&s. etc. Indentation corresponds to nesting level (as is done for most types of indentation).

You can treat the == operators the same as the logical operators and get this:

} elsif( StatusEvent::CONNECT_FAILED == $status->GetStateTransition() && CONNECT_TYPE_AUTO != $status->GetConnectType() || StatusEvent::DISCONNECTED == $status->GetStateTransition() && ( $IsAutoConnectDisabled || 0 == $statusNotAuto->GetTotalCount() ) && $statusNotAuto->GetTotalCount() == statusNotAuto->GetIdleCount() ) {

And how you cuddle the "}", "elsif(", ")", and "{" offers many WTDI that I see various trade-offs among; lots of room for personal style variations.

Anyway, you asked. (: Enjoy what style you pick (whether it includes parts of the above or not) and can get your cohorts to tolerate.

- tye