• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Braces Placement

R

ragtek

Guest
#1
I know, Kier & Mike prefers
PHP:
class Foo
{
    public function foo()
    {
    }
}
BUT, if you place the braces at the end of the line, the IDE will show the complete 1. line with the brace at the end and not only {
So, if it's placed in the same line as the class name, method head, "command"??(don't know any other word:D ), you'll see it, if it's in the next line, the IDE will only show the {

Example:
bad.PNG vs better.PNG
 

Kier

XenForo Developer
Staff member
#3
I know, Kier & Mike prefers
PHP:
class Foo
{
    public function foo()
    {
    }
}
BUT, if you place the braces at the end of the line, the IDE will show the complete 1. line with the brace at the end and not only {
So, if it's placed in the same line as the class name, method head, "command"??(don't know any other word:D ), you'll see it, if it's in the next line, the IDE will only show the {

Example:
View attachment 18586 vs View attachment 18587
I'm afraid that's an artefact of your IDE being retarded. Eclipse displays the function prototype correctly.
 
F

Floris

Guest
#5
I always have preferred

if (this) {
do this
} else {
do that
}

For some reason I used to read through that easier, and it was clear which } belonged to what ..

But the last 2 years I have moved away from this and made it a bit of a coding standard to use

if (this)
{
do this
}

Either way, it still doen't matter. But the longer your code becomes, the easier it is to make mistakes if the { } are on the lines of stuff you're handling. Doing it the second way, I made less mistakes with that.
 

Cezz

Well-known member
#6
I agree Floris, the first method is easier to read with small code, but the second method is a lot easier when your code gets larger, especially when used with correct tabbing also!