Where do you put the { } ?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply

Where to open the squiggle?

Same Line
15
68%
Next Line
7
32%
 
Total votes: 22

Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Where do you put the { } ?

Post 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.....
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Two lines down.
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

This was once discussed here: viewtopic.php?t=7671
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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"
}
?>
User avatar
EvilWalrus
Site Admin
Posts: 209
Joined: Thu Apr 18, 2002 3:21 pm
Location: Springmont, PA USA

Post 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
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Same line. Same reason as scorphus
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post 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 =]
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Post by uberpolak »

Same line - I'm very lazy.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Same line for everything except function, class and method declarations.

Mac
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

always same line, for the common reason...
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

w00t!! finally someone with a similar view!
Post Reply