Reader Level:

Using Regions to Improve Code Readability

By James Divine on Aug 26, 2003
Visual Studio .NET gives us some very handy tools to improve readability in our code.

An instructor I once had made a statement that has echoed in my head for years. When you are a programmer, you have two groups of end users, the people who will actually use the software, AND other programmers who may someday have to modify your code. With that in mind, I have always tried to write my code to be as easily readable to other programmers as possible.

Visual Studio .NET gives us some very handy tools to improve readability in our code. One that I am particularly fond of is the #region directive that allows us to collapse code in a customized manor.

Regions are created in this format:

#region MyRegion

your code here

#End Region

Everything that falls within the directives will be collapsible.

The method Ive chosen to adapt is to create regions for each different type of elements in a class (i.e. constructors, variables, methods, properties, enumerators) so that my code can be easily navigated.

Here is an example:

Doing this will keep your code more organized, which in turn will increase efficiency. And someday down the road when another programmer comes across your source code, they will be very thankful.

James Divine
James Divine

James is a Senior Software Developer with over 12 years experience working with web programming, desktop application programming, server application programming and handheld/mobil device programming. He has been working ... Read more



Spire.Doc - Free .NET Word API
Use Spire.Doc to create, read, write, print, and convert word documents to OpenXML, RTF, TXT, XPS, EPUB, EMF, HTML, Image and PDF.
Infragistics jQuery Controls

Trending up