Author |
Message |
Acaria Board Member

Joined: 20 Feb 2009
          Posts: 238

|
Posted: 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: 41

|
Posted: 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

|
Posted: 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

|
Posted: 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.  |
|
Back to top |
|
 |
Acaria Board Member

Joined: 20 Feb 2009
          Posts: 238

|
Posted: Wed Aug 12, 2009 2:42 am Post subject: Re: Does curly bracket placement matter? |
|
|
Thank you!  |
|
Back to top |
|
 |
drathbun Board Member

Joined: 24 Jul 2008
          Posts: 668 Location: Texas

|
Posted: 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.  _________________ phpBBDoctor Blog |
|
Back to top |
|
 |
|