Hmm...this is a constant quandary for me, when to use and when not to use the #region...#endregion tags(?) in code. Currently I tend to use them to hide pointless stuff like ASP.NET control declarations and  generally increase redability in long chunks of code (so, parcel up my events, constructors etc...in regions) - but I in no way always do this. Now, a colleague of mine uses this stuff religiously, every class has
  • Declarations
  • Lifecycle
  • General
  • Methods
  • Properties
; with all the bits all hidden away when you open the file (which incidentally drives me nuts - I'm a code-speed reader and it breaks the flow :-)). So here's a question, when do you use regions and where...and more importantly, anyone know a way to make regions expanded by default???
posted on Tuesday, February 15, 2005 3:51 PM | Print

Comments

Gravatar
# re: Regions in code - evil or not-so-evil?
Posted by Darrell on 2/15/2005 6:43 PM
Not so evil. I use them ocassionally for the method that is long and I just can't factor it out.
Gravatar
# re: Regions in code - evil or not-so-evil?
Posted by Scott Galloway on 2/16/2005 10:38 AM
Darrell - yup, pretty much the same here - it *does* looks tidy with all the regions but I don't really see the utility of having so many...
Gravatar
# re: Regions in code - evil or not-so-evil?
Posted by Joel Ross on 2/17/2005 7:44 AM
You can expand by default by going into Tools -> Options, and under Text Editor -> C# -> Formatting, you uncheck the checkbox by "Collapse #region blocks when files open"

That should take care of it.

Now, as for me, I use them, but I always struggle with how I should use them. Should they relate to types of entities (public methods, private properties), or functional entities (order processing, order detail methods)? Right now, I'm doing types of entities.
Gravatar
# re: Regions in code - evil or not-so-evil?
Posted by Scott Galloway on 2/17/2005 10:21 AM
Aha...umm...I should've known that really :-S I'm pretty much of the same thinking as Joel - I usually end up putting them in long sprawling classes (which I can't or won't refactor) to help readability of particular functional areas - I've never really seen the point of surrounding 'types' with them, so properties, page declarations etc...except if they make the code less readable...
Gravatar
# re: Regions in code - evil or not-so-evil?
Posted by joeycalisay on 3/10/2005 1:18 AM
Thanks for that info from Joel.

Actually it is a standard here at work and it is really hard for me to read those unnecessarily lines. Each property, method, etc. has their own region <sigh>, not to mention the major groupings on this post.
Post Comment
Title *  
Name *  
Email
Url
Comment *  
Please add 4 and 4 and type the answer here: