views:

57

answers:

3

As part of a project I am working on I have been asked to split all the code in classes into regions eg:

#region public methods
#endregion public methods

#region public properties
#endregion public properties

#region private methods
#endregion private methods

#region private properties
#endregion private properties

How should I classify internal properties and event handlers

+3  A: 

Don't do it!: Code regions are counter-productive. If you want to encapsulate code, extract it and put it into it's own class.

Needing regions is a sign you have too much code in one class/method, and is therefore breaking the Single Responsibility Principle.

See Jeff Atwood's post on the topic: The Problem With Code Folding

Mitch Wheat
Agreed, it doesnt sound like jat45 is in a position to change this guideline though. Breaking a faulty standard is worse then partially introducing a new one.
Martijn Laarman
+1 for the sign of too much vode and the link
Johannes Rudolph
Thanks - I will do my best to get the guidelines changed (I believe there is sufficient support for the change) and will get down to some refactoring instead.
jat45
I don't think code regions are bad per se. Of course abusing is bad, as with anything; but having clear at least which part of your class is public and which part is private is something that code regions can help to.
Konamiman
A: 

If your company or contractor has such specific coding guidelines it's best to verify with the project (technical) leader / manager who mandated this design pattern in the first place.

My guess:

#region internal methods
Martijn Laarman
Please don't use regions!
Mitch Wheat
Agreed, it doesnt sound like jat45 is in a position to change this guideline though. Breaking a faulty standard is worse then partially introducing a new one.
Martijn Laarman
A: 

If you really need to use regions, and if you are restricted to those given in your question, I would put the internal properties in the private properties region. The events are a bit trickier, but I guess I would put them among the private methods. If was was force to use exactly those regions that is.

If I was writing code for myself, it would look quite different...

Fredrik Mörk