Skip to main content
1 of 2
deceze
  • 2.3k
  • 1
  • 19
  • 19

Most readable way to format long if conditions?

Long winding if conditions should be avoided if at all possible, yet sometimes we all end up writing them. Even if it's a very simple condition, the involved statements are sometimes simply very wordy, so the whole condition ends up being very lengthy. What's the most readable way to format those?

if (FoobarBaz::quxQuux(corge, grault) || !garply(waldo) || fred(plugh) !== xyzzy) { thud(); } 

or

if ( FoobarBaz::quxQuux(corge, grault) || !garply(waldo) || fred(plugh) !== xyzzy ) { thud(); } 

or

if (FoobarBaz::quxQuux(corge, grault) || !garply(waldo) || fred(plugh) !== xyzzy) { thud(); } 

or

thudable = FoobarBaz::quxQuux(corge, grault); thudable ||= !garply(waldo); thudable ||= fred(plugh) !== xyzzy; if (thudable) { thud(); } 

or any other preferences?

deceze
  • 2.3k
  • 1
  • 19
  • 19