Page 1 of 1

Where do you put the { } ?

Posted: Mon Mar 08, 2004 12:49 am
by Steveo31
For instance, I use Flash Actionscript, and the syntax goes a little like this:

Code: Select all

function foo(){
//code
}
Notice the area of the open squiggly brackets. I've seen some use this format:

Code: Select all

function foo()
{
//code
}
Which do you prefer and why?

Curious.....

Posted: Mon Mar 08, 2004 1:10 am
by scorphus
On the same line. One line just for the oppening brace is a waste of space. There are already oppening 'keys' for blocks: for, if, function, while, etc. The identation itself does the job for visually (or really - python) delimiting a block.

Scorphus.

Posted: Mon Mar 08, 2004 1:12 am
by m3mn0n
Two lines down.

Posted: Mon Mar 08, 2004 1:19 am
by scorphus
This was once discussed here: viewtopic.php?t=7671

Posted: Mon Mar 08, 2004 11:17 am
by nigma
I prefer to put the braces on there own line. Reason? I think it makes things easier to read when you have many if, while, for, or other loops. If you only had one or two loops then I might not do things this way.

Example:

Code: Select all

<?php
if (condition)
{
   // Do "stuff"
}
?>

Posted: Mon Mar 08, 2004 2:03 pm
by EvilWalrus
For function declarations, i place them on the next line, however, for loops and conditionals, i keep them all in-line for readbility and optimization

Posted: Mon Mar 08, 2004 2:41 pm
by d3ad1ysp0rk
Same line. Same reason as scorphus

Posted: Mon Mar 08, 2004 4:37 pm
by tim
i think code looks sloppy or whatever if the beginning brace is on its own line.

I give the ending its own line, ie: like your flash example =]

Posted: Mon Mar 08, 2004 6:28 pm
by uberpolak
Same line - I'm very lazy.

Posted: Tue Mar 09, 2004 2:39 am
by twigletmac
Same line for everything except function, class and method declarations.

Mac

Posted: Sat Mar 13, 2004 10:15 am
by vigge89
always same line, for the common reason...

Posted: Sat Mar 13, 2004 11:59 am
by infolock
i always use next line. just looks more clean and organized, plus it's something you learn to do in delphi. hard to break old habits though.

but, i don't think that either way really matters. keeping it on seperate lines only uses, what? 8 bits? maybe less? just use whatever you think looks more organized, and makes your code seem to flow.

Posted: Sat Mar 13, 2004 2:01 pm
by nigma
w00t!! finally someone with a similar view!