Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silly question about how you format long if statements

Tags:

syntax

On long if statements where they take up more than one line, do you put the conditions like AND or OR on a new line like this:

               if (something
                   && something else)

Or like this:

               if (something &&
                   something else)
like image 417
Frodo Avatar asked May 26 '11 02:05

Frodo


1 Answers

For complex conditions, consider extracting it into a function or a variable:

if (complexCondition(foo)) { ..

As a bonus, the name of the function or variable can be used to communicate what the condition means. This makes your code easier to read.

like image 135
hammar Avatar answered Dec 15 '22 18:12

hammar