Formatting - Braces - Update

The position of braces in PHP code can be set up in the PHP formatting setting, category Braces(select item Braces in the Category combo box). It's possible to set up separately position of the brace after class declaration, function or method declaration and for other statements.

There are three values -  Same Line, New Line and Preserve Existing  that can be set to. The default value is Same Line.

Comments:

Pretty much all one needs. Thanks ;)

Posted by guest on February 07, 2010 at 05:37 PM CET #

Thanks, that looks very good. (You see, I found your edited post. ;) )

Posted by Xantiva on February 07, 2010 at 06:59 PM CET #

Yes! This is perfect! I'm personally a fan of new line on class and functions, same line on others.

Posted by foo on February 07, 2010 at 07:07 PM CET #

good work!

Posted by guest on February 07, 2010 at 11:47 PM CET #

Looks very good, thanks!!

Posted by Koen on February 08, 2010 at 01:04 AM CET #

Have you fixed this indentation of first brace? In 6.8 if you have braces on the next line, this happens if you write if($foo), press enter, press { and press enter:

if($foo)
....{

}

(... is just a tab placeholder)

It should be
if($foo)
{

}

Posted by Jasmo on February 08, 2010 at 01:09 AM CET #

This is better. I have problem with bracket at else

in your example:
if () {
}
else {

}

and i think better will be:
if () {

} else {

}

Is possible correct this ?

Posted by Ladislav Prskavec on February 08, 2010 at 01:09 AM CET #

To Jasmo: It should work now.

To Ladislav: I will try to add as new option for new lines category.

Posted by Petr Pisl on February 08, 2010 at 01:59 AM CET #

Well, this is good news. Finally NetBeans does support the PEAR coding standard! :)

However: the coding standard in our company demands that some structures ("if" and "switch") have the opening brace in the same line, while others ("while", "for" and "try") have the brace on the following line.

But I think that keeping the setting to "preserve existing" will do.

Posted by Tom on February 08, 2010 at 02:18 AM CET #

@Tom: IMHO your company has very strange "coding standards".

Posted by Jozef on February 08, 2010 at 11:40 AM CET #

Nice.
It will be even nicer, to align coding style, with CodeSniff checking, such as
http://www.whitewashing.de/blog/articles/122

In particular, default NetBeans indentation sniffs as an invalid style :(

Posted by Bruce Ingalls on February 08, 2010 at 01:14 PM CET #

Every new feature in this blog i reply with always the same issue. What netbeans lack is a support for svn password via ssh. I mean when we have to access an svn repository over ssh the program always prompt for the password. This issue is old and it make svn over ssh unusable

Posted by Mark on February 09, 2010 at 05:30 AM CET #

To Mark: I can not help you directly. I don't develop the svn support. I have talked with the guys about this, but I don't have such power as you, as user. Enter a new bug against the svn support. Push the svn support developers to fix it. I'm sure that these guys doesn't read this blog.

Posted by Petr Pisl on February 09, 2010 at 06:20 AM CET #

@Jozef I don't care if they are "strange". Most companies don't even have any such thing as a standard.

Every developer of course has an own idea of what "nice" code should look like. Take 10 developers and you possible will get 12 opinions of how to indent code, indent follow-up lines, maximum numbers of characters per line, format comments, indent braces, use of exceptions, or even how to comment SVN updates.

Note that others, like the PEAR coding standard, even demand a specific order of PHPDoc elements and a blank line after certain parts of your comment, or certain @-rules. PEAR also expects single-line comments with exactly 3 opening curly opening and closing braces around each function declaration. Where the function name and parameter list is copied to the opening comment.

Now this is what I would call "strange". However I believe it is some setting for a specific code editor, which needs these for code-folding. One day some core developer may have decided to use this specific editor and filed a standard that required all later developers to support it - forever.

Zend, for example, has a coding standard as well. This standard sometimes requires the opening bracket for a function body on a new line but for some cases require it to be on the same line, when there is a line break within the function head.
The same applies to if-blocks. They also demand that you MUST provide a @link block in your comments. So you MUST provide a unique URL for each package - even if it is not valid.

So: I guess we are really good off with our coding standard. ;)

Posted by Tom on February 09, 2010 at 08:41 AM CET #

@Tom: Thank you for "strange" examples. I am happy we have adopted the Sun Java coding standards for PHP projects too, because our primary job is Java ;-) http://java.sun.com/docs/codeconv/

Posted by Jozef on February 10, 2010 at 12:35 AM CET #

@jozef Yes. Actually our coding standard is based on the Java coding standard rather than using PEAR or Zend.

We also adopted the naming convention and e.g. the "fall through" comment for switch-statements.

However we introduced some minor modifications as it doesn't always seem to "fit" as well for PHP.

For example: the Java-style switch-statement does not follow the code-indention rules.
The Java naming convention allows pure verbs as function names. So "read()" would be fine for Java -> read what? Apples? Books? Files?

We also don't use java-style pre-formatted DocBlocks, since PHPDoc has a tag for that.

Also PHP does not have the same kind of variable shadowing that Java does. So we require that you unset() all loop-vars after the loop and that you check that they are not in use before you enter the loop. You simply don't need to do this in Java, so it's missing!

There are more of those examples.

In other words: you can't simply "copy" the Java coding-style to PHP. It won't work as well.

Posted by Tom on February 10, 2010 at 09:37 AM CET #

Offtopic: I think we need a post explaining the future of Netbeans and PHP in the hands of Oracle.

Thanks

Posted by Symfony Developer on February 10, 2010 at 12:00 PM CET #

Hi,

While this new feature is great, I haven't found a way to do this formatting:

function whatever()
<ident>{
<ident>...
<ident>}

if (...)
<ident>{
<ident>...
<ident>}
else
<ident>{
<ident>...
<ident>}

Is there a way to edit some template or something to achieve that?

Thank you.

Posted by Marco on February 11, 2010 at 03:55 AM CET #

To Marco: Unfortunately there is not a way how to do it now. I can extend the list of values with New Line Indented and probably New Line Half Indented?

Posted by Petr Pisl on February 11, 2010 at 05:24 AM CET #

Thanks Petr, maybe that would work, I will certainly try it.

Posted by Marco on February 17, 2010 at 03:50 AM CET #

An option for "new line (fully) indented" would be great indeed, as our company coding style requires it. Any progress on this? Thanks!

Posted by Brandon Harvey on November 15, 2010 at 04:13 PM CET #

To Brandon Harvey: Could you just file new issue in our bugzilla. It shouldn't be hard to implement this. Thanks.

Posted by Petr Pisl on November 18, 2010 at 06:20 AM CET #

OK, done! Bug 192127. Thanks...

Posted by Brandon Harvey on November 18, 2010 at 10:49 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

This blogs is written by NetBeans developers who contribute to the PHP support mainly.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today