Braces Placement

  • Thread starter Thread starter ragtek
  • Start date Start date
R

ragtek

Guest
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.webp vs better.webp
 
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.
 
That is specific to the IDE you use it seems as I have never experienced this myself!
 
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.
 
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!
 
Top Bottom