How clear is this? [Code Formatting Question]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moltendorf
    New Member
    • Jul 2007
    • 65

    How clear is this? [Code Formatting Question]

    I'm just wondering if I were to release some PHP program for others to use and mod if this would be a better way to format my code -- I'll give you all an example of how I've decided to format an if command.

    Placing each boolean on only one line, creating a line break before and after ( and ) if there hasn't been one created already, and one after any operators such as &&, and, or, ||, xor, etc...

    So, for example, is this new style:

    [PHP]if(
    (
    blah &&
    blah &&
    (
    blah ||
    (
    blah &&
    blah
    )
    ) ||
    (
    (
    blah &&
    blah &&
    (
    blah ||
    blah
    )
    ) &&
    (
    blah ||
    blah
    )
    )
    )
    )[/PHP]
    Better than...
    [PHP]if((blah && blah && (blah || (blah && blah)) || ((blah && blah && (blah || blah)) && (blah || blah))))[/PHP]

    By the way, I know that variables have $ in front of them.

    Just wanted some input from other various [probably more experienced] PHP coders that [obviously] use the if command quite frequently. :P

    If someone has a better example they could show me, please do so. :)
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    Hi,

    I'd probably go for the old style, makes it easier to follow the code...

    Good luck...

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Me too.. it confuses things when you start to split the code up.


      Does for me, anyway.

      Comment

      • nathj
        Recognized Expert Contributor
        • May 2007
        • 937

        #4
        Here's the third opinion and I'm in agrrement with the other two. Keep you IF condition together - it makes it easier to read.

        Cheers
        nathj

        Comment

        Working...