Re: Highlight Constructors in Eclipse ?
rossum wrote:
On Sat, 24 Nov 2007 13:43:09 -0800 (PST), Thomas Adrian
<notessidan@gmail.com> wrote:
Is there a way that to highlight all constructors in my sourcecode in
Eclipse, or any other indicator that can make it easy for me to see
that the methid is a constructor ?
I mean in the sourcecode, not in the outline.
Thanks
Thomas
I use:
//////////////////
// Constructors //
//////////////////
I use positional dominance.
When I lay out a class, I usually do it in the order:
class declaration
{
static compile-time constants
static variables
instance variables
static methods
constructors
instance methods
}
This is less egregious than it might look, because most classes with lots of
static methods won't have any instance methods or instance variables, and most
classes with instance variables, constructors and instance methods won't have
a lot of static methods. I avoid non-constant static members, at least not in
private, unless seriously forced to use them.
If a class is complex enough that that layout is not obvious, I use a similar
idiom to rossum's, but with fewer characters, either:
// constructors
or
/* constructors
*/
with blank lines above and below.
Also, the first word in my constructor Javadocs is always "Constructor":
/** Constructor - no-arg.
*/
In NetBeans (sorry Eclipse fans) I also set the menu entry:
Tools / Options / Fonts & Colors / Language = Java /
Options "Constructor Declaration" and "Constructor Use",
although in my case I use the same highlighting as for methods (bold, black).
I didn't find such an option in the preferences for Eclipse here.
I lay out enums quite differently. For enums, constant declarations and
bodies come first, then stuff that intuitively (to me) seems to explain what's
going on best. I haven't formalized that for myself yet, but it goes
something like this:
enum declaration
{
enum constants and their bodies
instance variables
constructor (don't know that I'd ever define more than one for an enum)
static method valueOf()
custom stuff for the enum (similar to regular classes henceforth)
}
Two things are mandatory. The layout should promote readability of the
source, and there must be complete Javadoc comments.
--
Lew