Technorati Tags:
C#,
Standards,
Opinion I often see arguments about use of regions in C# code. And this is one of the most annoying things I see on the Internet in my opinion when it pertains to code structure.
Whoever says regions are not to be used, I’d love to see your code and know what standards you have established as a team with your code base. I bet you it’s a mess and the reason you don’t like regions is because the developers on your team has abused use of them and that there is no logical pattern or team standard established.
I’ve been on plenty of teams who have used regions effectively and at a top level grouping that made classes and finding things much faster overall. I definitely agree that unorganized use of regions and overuse should not be, but to say not to use regions at all is like saying put all of your damn html on one line and don’t indent…another thing I can’t read.
If you have a team who can’t use regions effectively it’s either because of one or more of these three issues:
- They don’t care about team standards
- There is no pattern in place and standard that expected of the team
- There are no code reviews to help keep that standard and pattern in place
There is absolutely no excuse to say that regions are never helpful. It’s part of development, part your team standards/patterns people and then code reviews can help to reinforce it. It’s called caring about code structure which goes along with name spacing, file structure of you project, and pattern structure of your code. To single out regions is foolish and only means you can’t figure out a standard practice on your team and template to force and use that is top level..simple as this:
#region Methods
#region Properties
#region CRUDs
…whatever
Who wants to scroll down a class all the time when you can go to a region quickly to find what you want as a starting point. And your classes should never be very long (SOLID) but still, regions do help. If Code Generation did not use regions or non-generated code did not, can you imagine? Granted I am not using code generated code now but was and it was nice.
I always use regions and always will, they are not chaos in my application so they are extremely useful when not used like a code & run team who has no clue of standards or patterns. The argument not to use them should never come into play. If you see a bunch of regions and they are not named well, talk to the team and have a team meeting about it and come up with a template that works.
But never say they are ineffective and never to use them. Give me a break. You can say that about any aspect of code that is not organized and has no pattern or standard! Every developer is going to have to change code, and maybe regions will change but if used correctly not that often. That’s why it’s nice to use tools such as ReSharper to create and manage them as well. Having no regions with this type of “excuse” is just plain ignorance.
Print | posted on Sunday, April 19, 2009 10:05 PM