Monday, July 07, 2008

#region in C#

Jeff Atwood posted a nice article on Coding Horror about #region and code folding.

We should not write code which is useful for the editor and not for the compiler. Most of the IDEs already provide folding methods, and comments without writing anything extra. If you are using #region in a method, because it has too much code, then, probably, you may have to refactor the method. If you are using #region for set of methods, because you have too many methods, then probably, you may have to refactor the class.

Most of the developers prefer to read the code, and comments which explain about the code. But, not the directives to the editor.

One great thing about Visual Studio 2005 is, the search functionality will not search in the folded blocks. I really want to give Turing award to the person who came up with that requirement.

No comments:

Post a Comment