Style Issues
IDEA's refactoring and other features auto-generate a great deal of code. This is a wonderful thing, of course, but IDEA falls short on some stylistic issues. I'm starting this topic so people can list pet peeves.
-- JordanZimmerman
Field placement Top
I place all class fields at the bottom of the class. When IDEA adds fields, it tends to put them at the top of the class. E.g.
public class foo
{
public void bar()
{
}
private int i;
}
-- JordanZimmerman
You can modify the following values in <IDEA_HOME>/config/options/code.style.xml
<option name="FIELDS_ORDER_WEIGHT" value="1" />
<option name="METHODS_ORDER_WEIGHT" value="3" />
<option name="CONSTRUCTORS_ORDER_WEIGHT" value="2" />
<option name="INNER_CLASSES_ORDER_WEIGHT" value="4" />
Unfortunately, UI is not ready for customizing these fields.
-- MikeAizatsky - 31 May 2002
FYI - In newer versions, the code.style.xml is now in a different location. You can have multiple schemes. So, you the correct file is <IDEA_HOME>/config/codestyles/<scheme name>.xml
-- JordanZimmerman - 19 Aug 2002
Hey, that's great. Of course, I want more! I would like additional sorting based on scope. I put all public methods/fields at the top of the class, then package, then private. E.g.
public class foo
{
public static final int A_CONST = 1;
public void bar()
{
String my_string;
}
public int get_my_value()
{
return my_value_mbr;
}
public void set_my_value(int new_value)
{
my_value_mbr = new_value;
}
void pacakge_method()
{
}
int package_int_mbr;
private void private_method()
{
}
private int my_value_mbr;
}
-- JordanZimmerman - 31 May 2002
Any suggestions about flexible and clear set of options for member ordering are welcome.
-- ValentinKipiatkov - 04 Jun 2002
I'd love to see such a feature so I tried to imagine a GUI that I could work with.
We'd need to have a System that allows us to sort by multiple criteria:
- Access Modifier
- Type (variable, method, constructor)
- other modifiers
- by const-ness
- by final-ness
- ...
- name (alphabetically).
A simple list of Comboboxes would be a first step (i.e.: Order by "Access Modifier" first, then by "type", then by "name"). Of course it should be legal to only use of sorting criterium (someone might want to sort all members by name, ignoring case).
For each of these you'd need to specify how exactly to sort (by name is easy: ascending or descending, maybe ignoring get/set/; for access modifiers you should be able to arrange them any way you want ('though private/protected/package/public or the other way round will be most widely used).
-- JoachimSauer - 05 Jun 2002
Such a feature would be great. We've already posted some ideas on this topic in eap-features, Feb, 2002:
I agree with JoachimSauer's criterias. Even a UI is not necessary. Template files are more flexibel (e.g. to have also fixed text components, like method separators). Maybe the existing IDEA class template can be extended. A brief example:
public class $NAME$ {
// Constants -------- (This line should be printed in every class.)
$FINAL & STATIC & FIELD$
// Static -----------
$STATIC$
// Fields -----------
$FIELD$
// Setup ------------
$CONSTRUCTOR$
// Accessing --------
$PUBLIC & METHOD$
// Misc -------------
$OTHERS$
}
Now, all code-changing actions, like Layout Code/Refactorings/etc. should format/place their code according to the template. Then, actually, refactorings are 100%-automated ...
-- MarcStrapetz - 14 Jun 2002
Yes, Marc, this would be very good, because I would not need to move methods around in the files (especially after a Move method, Create Method/Constructor).
Currently IDEA places the moved methods always at the end of the class and I need to sort them in again. This limits the functionality of Move and Create methods for me.
-- ThomasSinger - 15 Jun 2002
Variable names Top
I name my variables all lowercase with underscores. If it's a class member, I append "_mbr". When IDEA inserts variables/fields, it assumes JDK style.
E.g.
public class foo
{
public void bar()
{
String my_string;
}
public int get_my_value()
{
return my_value_mbr;
}
public void set_my_value(int new_value)
{
my_value_mbr = new_value;
}
private int my_value_mbr;
}
-- JordanZimmerman
I use variable ScopeNaming? : the name indicates the scope of the variable.
private String __privateScope ;
protected String _protectedScope_ ;
String _friendlyScope ;
public String publicScope ;
Advantages :
- no need to [Ctrl-Q] : if it starts with '__', it's private, and nobody else but this class uses it.
- no collision with constructor parameter (no more this.value = value)
public ClassName (String param1)
{
__param1 = param1 ;
}
-- AlainRavet
Thinking about this - a template driven system like what's described above for variable placement would be very nice. It could even be done for methods (getters/setters).
$VARNAME$_mbr
get_$METHODNAME$
set_$METHODNAME$
or
__$VARNAME$
get$Capitalize(METHODNAME)$
set$Capitalize(METHODNAME)$
-- JordanZimmerman - 15 Jun 2002
|
|