Regions == Evil
I had an email thread at work with a bunch of the guys on regions and this is the concensus we generally have come to (some of the statements are theirs, not mine, just paraphrased here). I was once a convert who liked regions. I enjoyed them. They made me happy. In all the code I would do something like this:
class UserCondition : IActionCondition
{
#region Fields
private int _condition;
#endregion
#region Constructors
public UserCondition(int _condition)
{
this._condition = _condition;
}
#endregion
#region Properties
public int Condition
{
get { return _condition; }
set { _condition = value; }
}
#endregion
#region Public Methods
public bool CanExecute(string action, WorkItem context, object caller, object target)
{
string userName = Thread.CurrentPrincipal.Identity.Name;
return userName.ToLower().Equals("domain\\joeuser");
}
#endregion
}
That felt good and organized and neat (almost in an OCD way).
However I have seen the errors of my ways, as others have before me. Regions are evil. Pure and simple. The absolute incarnate concentrated type of evil that only the Time Bandits would fear and not the watered down, garden variety kind of evil.
They're great for hiding the annoying details of an IConvertible implementation or designer generated code (when it's not already in a partial class). But I often create methods on the fly using ReSharper and it is not going to look for the correct region to place the method. So having everything separated into regions actually slows me down because I have to find where to put the method.
ReSharper is your friend. Ctrl+F12 is all you need to find stuff in a file. Using ReSharper's type member layout to enforce code layout in a file, you can get consistency across all teams so one code file isn't vastly differently organized (say that 3 times fast) than any other project. With the custom pattern on, formatting puts all the members in all the right places and keeps layout and code style somewhat consistent across teams. It makes diff comparisons and merging a more pleasant experience.
Going forward, we're purging them from all projects and forbade use of them in new code. YMMV.