PDA

Click to See Complete Forum and Search --> : Regions - Any "standards"? [RESOLVED]


StrangerInBeijing
Sep 7th, 2005, 09:37 PM
Hi,

Regarding the use of "regions" in your code to organize things.

Are there any rules that tell you how not to use it, especially when it comes to nesting?

I nest the stuff like hell, but was told I am not to use nested regions for my work code.

OK, I can change that, but for my personal project, I use my own style, but would like to stick to any “unwritten” rules you pro’s might have

jmcilhinney
Sep 8th, 2005, 12:09 AM
The use of regions is purely for the developers benefit. It has no effect on anything other than how you view the code in the IDE. I try not to nest regions because it just makes it more difficult to get to the stuff I want, but if I have a particular region that is getting really large and there is a logical way to section it, then I'll think about nesting them. It's purely for the developers convenience though, and has no impact on your code whatsoever. If your company is of the view that nested regions make it more difficult to read code then that's their decision, but you should continue to do whatever you see fit in your own personal work.

MrPolite
Sep 8th, 2005, 12:52 AM
as jmc says it's up to you
however 2 notes that might relate to this:D
if you have a really long class and you want to break into different regions, you might want to consider c#2005's partial classes (if you are planning to get that).

vb.net doesnt allow regions inside functions and C# does. so if you're moving from vb.net you might not already know this. However, it might be a bad idea to use regions inside a function, because then it would mean your function is too long (it's usually a good idea to have shorter functions).

StrangerInBeijing
Sep 8th, 2005, 12:56 AM
thanks guys

reason for asking, is that I want to share code in my ssdev project if someone need help, whoever he/she are, so want to keep things to some kind of "standard".

partial classes...that's sth new..will look it up

thanks again

Sgt-Peppa
Sep 8th, 2005, 02:43 AM
I usually use regions that describe the kind of Functions, or members I use in my class.
For example:
#region using
.
.
.
#endregion

#region PrivateMembers
.
.
.
#endregion

#region PublicProperties
.
.
.
#endregion

#region PublicConstructors
.
.
.
#endregion

#region PrivateMethods
.
.
.
#endregion

#region PublicMethods
.
.
.
#endregion

#region PublicStaticMethods
.
.
.
#endregion

I do nest one more level inside the regions but thats absolutely it.
For example
#region PrivateMethods
#region static
#endregion
#region regular
#endregion
#endregion
This might not be the best use of them and theres probably millions of different ways on how to structure your code but I like it this way. And thats exactly how you should handle that topic. Do what you like, or how your company tells you to use them.
This was just to give you an idea on how someone else is using them.

HTH,

Stephan