phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

Does curly bracket placement matter?


 
Search this topic... | Search MOD Writing... | Search Box
Register or Login to Post    Index » MOD Writing  Previous TopicPrint TopicNext Topic
Author Message
Acaria
Board Member



Joined: 20 Feb 2009

Posts: 238



PostPosted: Mon Aug 10, 2009 5:47 am 
Post subject: Does curly bracket placement matter?

Like, okay, say I have something like this:


function exampleThing {

}


Could it also be written like this:

function exampleThing
{

}


without affecting the code? The second one seems more organized IMO, but I only really see the first method employed.

Does it matter which syntax I write in, or is it just my personal choice?
Back to top
ABDev
Board Member



Joined: 01 Jun 2009

Posts: 37


flag
PostPosted: Mon Aug 10, 2009 12:22 pm 
Post subject: Re: Does curly bracket placement matter?

A function must be written like this :

Code:
function my_function(params)
{
   code;
}


You can write like that too, if you want :

Code:
function my_function(params) {
   code;
}
Back to top
Ptirhiik
Board Member



Joined: 19 Nov 2008

Posts: 114


flag
PostPosted: Mon Aug 10, 2009 3:15 pm 
Post subject: Re: Does curly bracket placement matter?

Both are strictly the same regarding the execution. The first comes from javascript/java/AS3 style of language. I too prefer the second one, as it makes the blocks much more obvious, so dramaticaly increase the readability (what means less bugs, easiest to track down).
Back to top
Mrs Moo Moo
Board Member



Joined: 09 Mar 2009

Posts: 21



PostPosted: Tue Aug 11, 2009 10:24 am 
Post subject: Re: Does curly bracket placement matter?

I know many of these apply for phpBB3, but it definitely is best to follow the coding guidelines so that everybody else knows what it does. icon_wink.gif
Back to top
Acaria
Board Member



Joined: 20 Feb 2009

Posts: 238



PostPosted: Wed Aug 12, 2009 2:42 am 
Post subject: Re: Does curly bracket placement matter?

Thank you! icon_biggrin.gif
Back to top
drathbun
Board Member



Joined: 24 Jul 2008

Posts: 653
Location: Texas


flag
PostPosted: Sat Aug 29, 2009 3:06 am 
Post subject: Re: Does curly bracket placement matter?

To save someone the trouble of clicking the helpful link, the simple rule for phpBB is every brace { } goes on its own line. That's simple enough.

So this does not follow the standard:
Code:
If (test) { do something } else { do something else }

... even though the syntax is fine. The proper formatting as per standards is:
Code:
if (test)
{
     do something
}
else
{
     do something else
}

As per Ptirhiik this is also my preference, so I didn't have to change my habits. icon_cool.gif

_________________
phpBBDoctor Blog
Back to top
Display posts from previous:   
Register or Login to Post    Index » MOD Writing  Previous TopicPrint TopicNext Topic
Page 1 of 1 All times are GMT
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.0112 seconds using 15 queries. (SQL 0.0021 Parse 0.0003 Other 0.0088)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo