tags:

views:

150

answers:

2

SA1124 DoNotUseRegions suggest that region should not be used anywhere. Is it really reasonable?

I think region is a way to group relative code together and make large class easy to read, for example, if you generate interface method in for class, a region will be automatically inserted by visual studio.

I would like to remove this rule while checking code style. May I know your ideal on this rule?

+3  A: 

This is going to be a personal preference thing. The only thing that matters here is what you and your team prefer. Forget what style cop says, you're the ones reading it, you're the one's maintaining it, whether with or without regions works better for you, that's all that matters.

If you're releasing it as an open-source project...and this is my opinion here, I think the same applies. Use whatever the core team is more comfortable with. If you get a lot more team members aboard and more contribute, re-visit the issue later, this can always be changed.

Nick Craver
Isn't that backwards? They are the ones that *wrote* it, somebody as yet unnamed has to read it. And regions *definitely* make that awkward. My personal preference is to hate them when I have to read code.
Hans Passant
@nobugz - Currently, they're the ones dealing with it every day, going back over for bug fixing, etc...I'd still say they're reading it more than anyone else. Overall I consider it minor issue anyway, as you could string out all regions with a quick regex in no-time if needed. That and Ctrl+M+L makes it so I can use or ignore them pretty easy, but probably personal preference there.
Nick Craver
Well, I'm not that interested in reading buggy code. Surely SA1124 is a reminder. The point of a style cop is to *avoid* personal preference affecting the product.
Hans Passant
@nobugz - True, but then again, why was a feature added to only say it can't ever be used by the rules engine? Obviously there is some usefulness to some set of developers if it was added at all...seems to be a contradiction on StyleCop's part to me
Nick Craver
Or on the editor. I'll rephrase my previous comment to "affect the finished product".
Hans Passant
I agree that using region or not is an agreement inside team. Microsoft CAB project uses it, but Microsoft Enterprise Library 5 don't use it. I think most existed C# project are using region, because it sounds like a good grammar feature of C#. Using it, and avoid to be abused is a my preference.
Yanhua
A: 

I think that regions can be abused, but they are a useful technique for allowing a reader to focus on certain areas of the code at a time.

I would avoid too many levels of nesting, however.

John Saunders
Abused on using region can make browsing code unfriendly. In my practice, I don't use any nest region and only region Fields, Properties, Constructor, Interface implementation, Public methods, Private and Help methods.
Yanhua