Geeks With Blogs
Drewby Made from 60% post-consumer recycled fiber.

If you've spent much time in Visual Studio .NET, you've probably discovered the ability to create regions in your code that can be collapsed using the outlining features in Visual Studio. It lets you hide some of the clutter in a class file. VS.NET puts most generated code in a region to hide it away from developers.

Over the past couple years using VS.NET, I've struggled with how to best use this feature. It seems that there are couple ways to approach regions:

  • Public/Private/Protected - One region for each access modifier keyword. This would organize your code in a similar way to how C++ code is organized.
  • Member Type - One region for each type of member: Fields, Properties, Methods, etc.
  • Behaviour - A region that groups members by the a more granular behavior or role in the class. For example, grouping all CRUD methods together in one region and all Calculation methods in another region.
  • There are probably others...

I go back and forth on what the best organization is. It seems like in some situations one strategy is clean and simple, yet in another situation it just gets in the way. It would be nice if I could settle myself on one strategy for regions or just convince myself not to use them at all.  I wonder how others have developed best practices around this feature.

One last thought. It seems like some developers are so good at organizing and writing code that there is no need for regions to hide clutter. I hate you. ;)

Posted on Wednesday, March 24, 2004 11:14 AM .NET | Back to top

Copyright © Drew Robbins | Powered by: GeeksWithBlogs.net