coding standards - sections in class files

  • Thread starter Thread starter Jon Paugh
  • Start date Start date
J

Jon Paugh

Is there a standard for where to put the different
categories of code in a class file? For example, after the
class declaration, normally I put class variables, then
constuctor, then private methods, public methods, then
properties etc. Is there a standard for this order?

Anyone know of a good template in CodeSmith or in the MS
VS template language that seperates the different pieces
of code?

Thanks!

Jon Paugh
 
Jon:

That's one of the cool features of VS.NET, you can come up with what works
best for you and then enforce it with Regions. #Region SomeRegion

ABunchOfMethods

#End Region
 
The more I use regions, the more specific I find myself getting. In a
recently-coded class, for instance, I defined regions for:

Constructors
Constants and data (you could divide these into static and instance regions)
Static methods, if any, including the static constructor if supplied
Base class overrides
Public properties
Public methods
Protected properties
Protected methods
Private members (usually methods, and very rarely private properties)
OnXxxxxx methods (for controls, which have a panoply of protected methods
like OnClick, OnMouseDown, etc.)
interface implementations (e.g., IEnumerable, IDisposable, etc.) with one
region for each interface
Event handlers

I think the order of your regions is up to you, but it seems to make sense,
for me anyway, to put them in more or less the order I listed them above:
constructors, implementation data, static members, base class instance
overrides, and then public, protected, and private members in order of
visibility, followed at the end by the bookkeeping sections (the
interfaces), and finally the event handlers (at the end because that's where
the IDE creates them when you go through the Events user interface).

If the IDE had a key combination or context menu item for "collapse all
regions", I'd be ecstatic but I haven't found such a thing yet.

Best regards,
Tom Dacon
Dacon Software Consulting
 
Sure, but if there were a standard we would use it. And I
do see some ad-hoc sorts of standards at least starting to
develop based on seeing some consistantly named regions in
unaffiliated authors code.
 
Back
Top