 |
Placement Of Private Fields
Should private members appear at the top of a class or at the bottom?
The case for the top:
- seems to be most common, so one might argue that it is expected by most programmers
- is recommended by the Sun's coding conventions
- it emphasizes implementation over interface
The case for the bottom
- C++ culture seems to prefer this style (how about other cultures?); for example, the Design Patterns and Effective C++ book use this style exclusively
- in this interview with Joshua Bloch, he states that "I wouldn't take that document (Sun's coding conventions) too seriously. It is not actively maintained or used at Sun."
- it emphasizes interface over implementation
- it allows a natural drill down from greater to lesser scope
One might argue that the javadoc should be used for the task of understanding interface, while code should be used to understand the implementation. But why force readers to do that? Would it not be better to allow them the choice?
It seems natural that the least important items should appear at the bottom of the class, not the top.
-- JohnOHanley - 21 Jun 2003
Discussion
|