We have reduced support for legacy browsers.

What does this mean for me? You will always be able to play your favorite games on Kongregate. However, certain site features may suddenly stop working and leave you with a severely degraded experience.

What should I do? We strongly urge all our users to upgrade to modern browsers for a better experience and improved security.

Kongregate is a community-driven browser games portal with an open platform for all web games.
Get your games in front of thousands of users while monetizing through ads and virtual goods.
Learn more »

About curly braces

I thought it was more popular to write them on their own lines:
`
if(variable == true)
{
//code here
}
`
But auto format in Flash puts the curly braces right after the parenthesis:
`
if(variable == true){
//code here
}
`
Out of curiosity, I was wondering which style is more popular/widely used.
I used to use the second style, but I finally got into the habit of doing it the other way.

> *Originally posted by **[GameBuilder15](/forums/4/topics/335879?page=1#posts-7030013):***
>
> I thought it was more popular to write them on their own lines:
>
> `
> if(variable == true)
> {
> //code here
> }
> `
>
> But auto format in Flash puts the curly braces right after the parenthesis:
>
> `
> if(variable == true){
> //code here
> }
> `
>
> Out of curiosity, I was wondering which style is more popular/widely used.
>
> I used to use the second style, but I finally got into the habit of doing it the other way.
It’s entirely preference, I don’t know if there is a graph on who uses what but I’m partial to this:
`
if (foobar == true)
{
//derp
}
`

Funnily enough, I use the first when programming in AS3, and the second when programming in Java, just to illustrate how insignificant the difference is
I prefer the first aesthetically, but many IDEs, e.g. Eclipse, are based around the second format, so sometimes it’s just best to stick with how the IDE wants to play ball to prevent the need to alter settings and/or constantly edit pre-formatted code

I used to use the first style, but switched to the second because it takes up one less line for the same logic. This increases the amount of logic that I am able to view on my screen assuming that the code’s length is beyond a screen. It’s much easier to troubleshoot a problem when you view as much of the relevant code to the problem as possible, as opposed to having to scroll down or up slightly.

I put the braces on the same line (i.e. the second way) because of the same thing, I hate wasted space because it hides logic. If it’s a one line condition I won’t have separate lines at all, just do
`if(whatever) { do_stuff; }`
(or sometimes no braces, depending on how lazy I’m feeling).

> *Originally posted by **[evan999333](/forums/4/topics/335879?page=1#posts-7030340):***
>
> I like the second personally
> Edit\>Preferences\>Autofomat
> check “Inset { on line after if, for, switch, while, etc.”
Oh, cool. I didn’t know you could do that.

Yeah, entirely preference. Personally, I like:
`
public function CreateCupcake():void
{
trace("Yaay! I now have a cupcake!");
}
`
My reason being is that it’s faster (for me) to, at a glance, mentally identify and isolate which logic is part of which block, as well as ensure that there aren’t any brace/bracket failures going on.
This for single-liners, because (unless I’m missing something) the braces aren’t necessary:
`
if (cupcake.flavor == Cupcake.CHOCOLATE) trace("*Squeals in delight*");
`

Thanks for the link, I didn’t realize how many indent styles there where. I put open braces on their own line, I like to see them align with their corresponding closing brace. And yes, curly braces are usually superfluous when they only embrace a single instruction, such as
`
for (var i:int = tray.length - 1; i >= 0; --i) tray[i] = new Cupcake();
`
instead of
`
for (var i:int = tray.length - 1; i >= 0; --i)
{
tray[i] = new Cupcake();
}
`
which does wonders for compacting code. So does replacing the contents of the curly braces with a single function call, and displacing the ‘guts’ to their separate function. It can reduce nesting as well.

> *Originally posted by **[Ace\_Blue](/forums/4/topics/335879?page=1#posts-7031602):***
>
> And yes, curly braces are usually superfluous when they only embrace a single instruction
Unless you want to add a trace statement in there to see if that line of code is being run, in which case it’s convenient to have the braces already there.

Surprising this hasn’t erupted into a flame war.
I prefer non-nestled curly braces. AFAIK, nestling them IS more common overall. But for some reason, the flash community tends to prefer to not nestle them.

I think that this:
thing
{
}
looks like garbage and it doesn’t make anything more readable. Some say its easier to match code blocks and I think it’s just as easy without. Others like that there is a line of [mostly] white space before and after each code block, that makes total sense so what I do is
if(something){
doSomething();
}