Formatting: Group Multiline Alignment - Added

One week ago I have added two new properties for formating PHP code into NetBeans 7.1. In Alignment category there are new properties for Group Multiline Alignment - Assignment and Array Initializer. 



The Assignment property influence position of the char '=' in a group of lines with assignments.  Let see the pictures below. 



On the left site -  Assignment property is off and on the right site the property is on. As you can see, when the property is set on, then the assignment char '=' is placed after the longest identifier in a group. The group is defined as a number of lines that contains the same type of assignments. End of a group can be empty line, line where is only a comment, different expression, end of a block. This formatting options works for variable assignment, field initialization and constants. 


The second new property is for Array Initializer.  



Both properties are switched off by default.


If you will play with it, please file any problem into our Bugzilla.  

Comments:

Hi Petr,

Thanks for all your hard work - however, I think though it looks good but it is somewhat retrograde - in fact, this is the subject of Sam Marshall's rant here: http://learn.open.ac.uk/mod/oublog/viewpost.php?post=74901

I couldn't agree more.

Regards

Posted by taatparya on November 14, 2011 at 10:23 AM CET #

I agree and I don't use this approach. But there is issue in our Bugzilla http://netbeans.org/bugzilla/show_bug.cgi?id=187734 with 8 votes, that people want to this. I have also got a few personal messages that some people have such coding style.

By default it's switch off. So if you want to use it, you have to manually set up it.

Posted by Petr Pisl on November 14, 2011 at 10:44 AM CET #

When is the Netbeans 7.1 going to be out of beta ?
We need the Git support.

Posted by Daniel Gafitescu on November 15, 2011 at 02:53 AM CET #

wow

Posted by guest on November 15, 2011 at 04:27 AM CET #

I always use a proportional font, so this wouldn't work for me, but mileage may as they say vary.

Posted by Papa Smurph on November 15, 2011 at 01:50 PM CET #

I don't agree with the guy ranting about this. The reason for his rant was that he had no IDE support for this style (possibly no column/rectangular edit mode either) and thus he argues that the indention deteriorates over time and causes extra work to maintain by hand, because "code is not carved in stone".

Now this post changes the whole game. Because with this update the Netbeans IDE actually does it AUTOMATICALLY if you want it.
If it is done automatically, then there is no extra work and the layout cannot deteriorate over time. Thus all his arguments are void.

The only reason left will be old-school SVN diff views that mark changes in white-space areas as changes. This is a nuisance but more up-to-date clients today allow to ignore these changes so that this does not need to be an issue either.

Your choice. For me: I didn't use it so far, because it was too much of an effort. However, with that extra effort gone I might start using it now. It really makes large blocks easier to read and whatever helps developers to read my code is very much appreciated.

Posted by Tom on November 15, 2011 at 03:57 PM CET #

Nice feature!

There is no right or wrong as assumed in the linked article by taatparya. It depends on the agreement a development team makes as coding style convention. It's more about personal opinions. That's why it is an option I guess!

Personally I think that readable code like this makes it easier to maintain it in a later stage.

Just make sure to be consistent in choice! I like it anyway :-)

Posted by guest on November 16, 2011 at 03:31 AM CET #

This option is not available in the Linux version of the beta? I downloaded it and there is no option as seen in your screenshots.

Posted by Zachary on November 16, 2011 at 12:38 PM CET #

Great function, Thanks !

Posted by fortruth on November 17, 2011 at 10:59 AM CET #

@Zachary: No this was added after beta. It's available in nightly builds, or you can wait for RC1, that will be available very soon.

Posted by Petr Pisl on November 18, 2011 at 07:50 AM CET #

Hi...
Thanks for all the great features but I would like to make a suggestion. I also work with visual studio 2010 and I fell in love with a feature. When you type if, foreach, switch, do, etc - then hit tab twice you get a protoype of that operation. For example:

foreach <tab><tab>

editor writes:

foreach ($collection as $key=>$value){
//

}

I would love that in netbeans...If you have to do a few hundred a day it saves a lot of shifted keystrokes!

You should also have a look at their re-factoring menu - It works very well.

Posted by guest on November 25, 2011 at 10:28 PM CET #

NetBeans has something similar. There code templates, if you go to the Tools->Options->Editor->Code Templates. Select the language in the combobox and you should see the predefined templates. Every templates has an abbreviation. You can read also there: http://blogs.oracle.com/netbeansphp/entry/code_templates_in_netbeans_php

Posted by Petr on November 29, 2011 at 02:31 AM CET #

Love this feature. Perhaps a suggestion to also do alignment on multiline object property assignments. Thanks!

Posted by guest on August 21, 2012 at 08:24 PM CEST #

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