PHP: control structure syntax ( ':;'s / '{}'s )

Discussion in 'Hardware' started by jezmck, 25 Jul 2006.

?

Which control structure(s) do you use and why?

  1. {} - Traditional brackets/braces only

    86.7%
  2. if:...endif; - 'colon syntax' only

    6.7%
  3. A mixture

    6.7%
  4. Other

    0 vote(s)
    0.0%
  1. jezmck

    jezmck Minimodder

    Joined:
    25 Sep 2003
    Posts:
    4,456
    Likes Received:
    36
    Which do you use, and why?

    ----

    Edit: personally I use the braces, mainly because I started programming in Java and they work. I have been thinking I should change, but couldn't think of a good reason why.
     
    Last edited: 25 Jul 2006
  2. CaseyBlackburn

    CaseyBlackburn Network Techie

    Joined:
    27 Jul 2004
    Posts:
    1,846
    Likes Received:
    0
    Traditional Brackets just on account of I get a better feel of just what is in process, but that is just me.
     
  3. DougEdey

    DougEdey I pwn all your storage

    Joined:
    5 Jul 2005
    Posts:
    13,933
    Likes Received:
    33
    Braces, cos I do more C++
     
  4. ajack

    ajack rox

    Joined:
    17 Apr 2003
    Posts:
    2,695
    Likes Received:
    2
    If it's just a small loop, braces. If it's a hauuuge loop, if: endif; - seems more logical imho.
     
  5. jezmck

    jezmck Minimodder

    Joined:
    25 Sep 2003
    Posts:
    4,456
    Likes Received:
    36
    more logical? how? (just curious, not disagreeing)
     
  6. Firehed

    Firehed Why not? I own a domain to match.

    Joined:
    15 Feb 2004
    Posts:
    12,574
    Likes Received:
    16
    Almost exclusively braces. I've got a little system worked out for getting things lined up just right in my editor, and it makes it ten times easier to keep track of what ends where. I rarely even have { quick thing; } on one line like that, just because it's nonstandard and tends to throw me off a bit.
     
  7. eek

    eek CAMRA ***.

    Joined:
    23 Jan 2002
    Posts:
    1,600
    Likes Received:
    14
    Always braces, I like to have things consistent throughout :)
     
  8. Nath

    Nath Your appeal has already been filed.

    Joined:
    28 Dec 2003
    Posts:
    2,409
    Likes Received:
    1
    Braces pretty much always, would probably get confused with endif; etc. so I just stick to what I understand. :)
     
  9. Hwulex

    Hwulex What's a Dremel?

    Joined:
    1 Feb 2002
    Posts:
    4,007
    Likes Received:
    1
    I can understand ajack's pov. If I've got very large if statements, or several nested statements, then just lots of end braces:
    Code:
    			}
    		}
    	}
    }
    Can be confusing. If you have this, however:
    Code:
    			endif;
    		endif;
    	endwhile;
    endif;
    It's immediately easier to quickly identify what's closing what without the need for comments.


    Having said that I exclusively use curly braces. :D I did use colon syntax for short perioud of time, as much as anything just to pee off my colleague, but then when I found out I was going to have to write something to pillage and profile our code I didn;t want to have to write something that handled colon notation. :duh:
     
  10. jezmck

    jezmck Minimodder

    Joined:
    25 Sep 2003
    Posts:
    4,456
    Likes Received:
    36
    'tis a good point, though the comments I generally leave at a closing bracket (if it's a long way from the opening) also state what the loop (/if) was for.
    But I guess it'd be better than brackets if minimal / no comments are left.
     
  11. simon w

    simon w What's a Dremel?

    Joined:
    3 Nov 2003
    Posts:
    1,302
    Likes Received:
    0
    But it doesn't tell you which if statement your closing.

    This is what shift+5 is for in vim.
     
  12. eek

    eek CAMRA ***.

    Joined:
    23 Jan 2002
    Posts:
    1,600
    Likes Received:
    14
    So long as you indent properly then it should be obvious what your closing - just a matter off following the bracket vertically! :)
     

Share This Page