Naked dot - accessing object fields through unqualified "." [C1]
Joseph D. Darcy
Joe.Darcy at Sun.COM
Tue Mar 24 10:16:38 PDT 2009
Alexandre MAKARENKO wrote:
> Naked dot
> AUTHOR(S): MAKARENKO Alexandre
> FEATURE SUMMARY: Accessing object fields through unqualified "."
> MAJOR ADVANTAGE: Obsoletes attribute naming conventions.
> MAJOR BENEFIT: Makes Java programs visually more readable and eventually
> less error-prone (see ?Strict mode? in details).
> To avoid name collisions and make source codes more maintainable
> developers either hold with a convention for attribute names or prefix
> members by ?this.? when refer to. Any naming convention, since not a part
> of the language, offers only a weak distinction between local variable and
> object field. Moreover it introduces extra characters and makes the source
> code not very natural. Using ?this.? is absolutely safe but makes the
> source code too much heavy.
> Assessing object fields through unqualified ?.? may be an elegant
> trade-off between readability and strictness.
> MAJOR DISADVANTAGE: May look assemblish.
> Use "this.aField" or m_aField, or _aField, or any other naming convention
> to distinguish between local variables and object fields.
> public class Point
> public Point( double x, double y )
> .x = x; // compiles like this.x = x;
> .y = y; // compiles like this.y = y;
> private double x, y;
I don't think being about to elide "this" in such situations would be
very helpful; at least having to write out "this.x" gives some clear
indication you aren't assigning x to itself!
More information about the coin-dev